[python] arch linux install mysql and use with python

1. 概述

Relational database like MariaDB is one of the required components to setup a web server as well as other less common uses such as when configuring a shared Kodi database. On Arch Linux MySQL has been replaced by a functionally identical community fork called MariaDB. The installation is also practically identical and as simple as can be expected.

2. 安装 MySQL / MariaDB

Install with pacman.

sudo pacman -S mariadb

Initialize data directories.

> sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

Two all-privilege accounts were created.

One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.

After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
Get Involved

By default MySQL will run as the user running the command unless a user is explicitly

specified with –user option. Path to the installation directory can be specified with –basedir option while data directory is specified with –datadir.

3. 运行 MySQL / MariaDB

Start the service with systemd & Enable the service to start on boot.

sudo systemctl start mysqld     #启动
sudo systemctl enable mysqld    #开机启动

Then reboot!

4. 配置 MySQL / MariaDB

Secure the installation.

sudo mysql_secure_installation

Make sure you set root password, remove anonymous users and disallow root login remotely unless you know you will need remote access to MariaDB. There should also be no need to keep test database so remove test database and access to it. Finish the install process with reload privilege tables now.

5. 使用 MySQL / MariaDB

Invoke the command line tool.

The username is specified with -u option follower by the username which is root by default. The password is specified with the -p option followed by the password without a space in between or the password can be omitted in which case MariaDB will prompt for one.

  • List all existing databases.
SHOW DATABASES;
  • List all database users.
SELECT DISTINCT User FROM mysql.user;

Use command line or Install phpMyAdmin to administer MySQL / MariaDB databases.

通过下面命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功:

sudo netstat -tap | grep mysql

登陆mysql数据库可以通过如下命令:

mysql -u root -p

-u 表示选择登陆的用户名, -p 表示登陆的用户密码,上面命令输入之后会提示输入密码,此时输入密码就可以登录到mysql。

下面是一些命令行中操作的DEMO,可做今后参考:

mysqladmin -u root -p create blog
mysql  mysql -u root -p
show databases;
use blog;

CREATE TABLE IF NOT EXISTS blog_table(
   blogId BIGINT UNSIGNED,
   url VARCHAR(100) NOT NULL,
   title VARCHAR(1000) NOT NULL,
   support INT UNSIGNED,
   pageView INT UNSIGNED,
   PRIMARY KEY ( blogId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS tag_table(
   tagId INT UNSIGNED AUTO_INCREMENT,
   tagName VARCHAR(100) NOT NULL,
   PRIMARY KEY ( tagId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS blog_tag_relation_table(
   relationId INT UNSIGNED AUTO_INCREMENT,
   blogId BIGINT UNSIGNED,
   tagId INT UNSIGNED,
   PRIMARY KEY ( relationId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

show tables;
desc blog_table;
desc tag_table;
desc blog_tag_relation_table;

//change blogId int 2 bigint
alter table blog_table change blogId blogId BIGINT UNSIGNED;
//show data
select * from blog_table;
//delete data
delete from blog_table where blogId=201801021423;

INSERT INTO blog_table(blogId,url,title,support,pageView)
VALUES(201801021423,'http://106.14.226.191:3000/blog/201607281658.html','[商业_法务] 1、公司一款新消费类电子产品如何快速全面的专利保护',0,0);

//too short
alter table blog_table change title title VARCHAR(1000) NOT NULL;

INSERT INTO tag_table(tagId,tagName)
VALUES(0,'硬件_模拟电路');

select * from blog_table;
select * from tag_table;
select * from blog_tag_relation_table;

delete from blog_table where blogId>0;
delete from tag_table where tagId>=0;
delete from blog_tag_relation_table where relationId >= 0;

select a.title , a.url, b.tagName from blog_table a, tag_table b, blog_tag_relation_table c WHERE a.blogId = c.blogId AND a.blogId = 201602021408 AND b.tagId = c.tagId;

select a.title , a.url, b.tagName from blog_table a, tag_table b, blog_tag_relation_table c WHERE a.blogId = c.blogId AND b.tagId = c.tagId ORDER BY b.tagId;

为了python操作mysql需要执行下面命令:

pip install MySQL-python (arch linux 2.7 版本 python 会报错,建议用下面的命令)
sudo pacman -S mysql-python

链接

: 在 ubuntu 上比较好操作,在 arch linux 上有些难操作,这里记录下~

[python] arch linux install mysql and use with python

Original: https://www.cnblogs.com/zjutlitao/p/15357949.html
Author: beautifulzzzz
Title: [python] arch linux install mysql and use with python

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585661/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 初识前后端

    初识前后端 在学习了解前后端的过程中,自己看到了这一篇好的文章,摘下了一些当下用的的内容,供复习参考。 什么是前端开发? 前端开发主要涉及网站和 App,用户能够从 App 屏幕或…

    Linux 2023年6月13日
    0103
  • Centos系统部署nginx1.18.0

    镜像下载、域名解析、时间同步请点击阿里云开源镜像站 一、 安装依赖包 yum –y install gcc gcc-c++ openssl openssl-d…

    Linux 2023年5月27日
    082
  • 国产银河麒麟Kylin V10操作系统

    今天想在国产银河麒麟Kylin V10操作系统中设置win+E显示资源管理器(我的电脑)的快捷键,首先需要判断麒麟操作系统使用的哪种桌面, 在终端Terminal中执行 echo …

    Linux 2023年6月14日
    084
  • java内存调优总结

    ···bashJVM 调优,是个很简单也很复杂的话题,由于经常遇到这类问题,在这里总结一下。 先从解决bug开始,当Java程序申请内存,超出VM可分配内纯的时候,VM首先可能会G…

    Linux 2023年6月14日
    079
  • JDK8-Lambda 表达式

    Lambda 表达式 Lambda 表达式是 JDK8 的一个新特性,可以取代大部分的匿名内部类,写出更优雅的 Java 代码,尤其在集合的遍历和其他集合操作中,可以极大地优化代码…

    Linux 2023年6月13日
    065
  • Windows Terminal 配置oh-my-posh主题 记录

    reference https://cloud.tencent.com/developer/article/1538644https://cloud.tencent.com/dev…

    Linux 2023年6月6日
    095
  • linux 普通分区与lvm分区

    安装linux系统时 有时候会提示lvm分区与标准分区 首先普及一下lvm分区:lvm是 logical volume manager (逻辑卷管理),linux环境下对磁盘分区的…

    Linux 2023年5月27日
    088
  • 根据温度、气压计算海拔高度

    基本概念 标准大气压:表示气压的单位,习惯上常用水银柱高度。例如,一个标准大气压等于760毫米高的水银柱的重量,它相当于一平方厘米面积上承受1.0336公斤重的大气压力。由于各国所…

    Linux 2023年6月8日
    086
  • CenterOS对防火墙和端口号的操作

    1 防火墙设置 (1)设置开机启用防火墙:systemctl enable firewalld.service (2)设置开机禁用防火墙:systemctl disable fir…

    Linux 2023年6月7日
    078
  • JAVAssist字节码操作

    Java 动态性的两种常见实现方式 字节码操作 反射 运行时操作字节码可以让我们实现如下功能: 动态生成新的类 动态改变某个类的结构(添加/删除/修改新的属性/方法) 优势: 比反…

    Linux 2023年6月13日
    088
  • LVS 负载均衡集群

    1.1 LVS介绍 LVS 是 Linux Virtual Server 的简写,即 Linux 虚拟服务器,是一个虚拟的服务器集群系统。此项目在 1998 年 5 月由章文嵩博士…

    Linux 2023年6月6日
    080
  • WEB安全信息收集

    每次做测试都要去网上找信息太费劲这里放了常用的所有工具和网站,后期有更新在改。 子域名&敏感信息 通过大量的信息收集,对目标进行全方位了解,从薄弱点入手。 利用Google…

    Linux 2023年6月7日
    073
  • ​Linux知识点总结(内附思维导图,建议收藏)

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月7日
    091
  • redis持久化存储

    redis持久化存储 redis多被用于缓存和消息中间件,当被用作缓存时,数据的读写都是在内存中进行的,而内存一旦在主机断电或者主机重启时里面的数据将被清空,为保证数据不被丢失,r…

    Linux 2023年6月7日
    095
  • SQL87 最差是第几名(一)

    本题链接表结构如下所示。 +——-+——–+| grade | number |+——-+&#8…

    Linux 2023年6月13日
    074
  • [转帖]bash shell学习之变量

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年5月28日
    076
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球