Arch Linux 安装 MySQL 8.0
目录
第一步: 更新源
更新软件仓库
sudo pacman -Syy
查看软件仓库 MySQL 版本
pacman -Si mysql
结果如下:软件仓库的 MySQL 已经是最新版
软件库 : archlinuxcn
名字 : mysql
版本 : 8.0.11-1
描述 : Fast SQL database server, community edition
架构 : x86_64
URL : https://www.mysql.com/products/community/
软件许可 : GPL
组 : 无
提供 : mariadb=8.0.11
依赖于 : mysql-clients libsasl zlib jemalloc libaio libtirpc
可选依赖 : 无
冲突与 : mariadb
取代 : 无
下载大小 : 18.90 MiB
安装后大小 : 190.68 MiB
打包者 : lilac (on behalf of Winston Wu) <winstonwu91@gmail.com>
编译日期 : 2018年05月09日 星期三 09时53分47秒
验证者 : MD5校验值 SHA-256 校验值 数字签名
第二步: 安装 MySQL
安装命令如下:
sudo pacman -S mysql
安装成功之后, 会看到如下提示
正在解决依赖关系...
正在查找软件包冲突...
软件包 (3) libmysqlclient-8.0.11-1 mysql-clients-8.0.11-1 mysql-8.0.11-1
全部安装大小: 239.58 MiB
:: 进行安装吗? [Y/n]
(3/3) 正在检查密钥环里的密钥 [################################] 100%
(3/3) 正在检查软件包完整性 [################################] 100%
(3/3) 正在加载软件包文件 [################################] 100%
(3/3) 正在检查文件冲突 [################################] 100%
(3/3) 正在检查可用硬盘空间 [################################] 100%
:: 正在处理软件包的变化...
(1/3) 正在安装 libmysqlclient [################################] 100%
(2/3) 正在安装 mysql-clients [################################] 100%
(3/3) 正在安装 mysql [################################] 100%
:: You need to initialize the MySQL data directory prior to starting
the service. This can be done with mysqld --initialize command, e.g.:
mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
:: Additionally you should secure your MySQL installation using
mysql_secure_installation command after starting the mysqld service
:: 正在运行事务后钩子函数...
(1/3) Reloading system manager configuration...
(2/3) Creating temporary files...
(3/3) Arming ConditionNeedsUpdate...
第三步: 初始化
这条命令是怎么来的 ? 仔细查看安装 MySQL 的输出信息
sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
执行结果如下:
2018-07-23T05:14:35.606101Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-07-23T05:14:35.606432Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 12937
2018-07-23T05:14:37.530922Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gyLkhoMTo2.w
仔细查看输出结果你会发现:
- 默认已经创建了一个 SQL 用户,
- 用户名: root@localhost
- 密码: gyLkhoMTo2.w
你的密码和我的不一定一样, 以命令行输出为准
第四步: 开机自启
sudo systemctl enable mysqld.service
第五步: 启动 MySQL 服务
启动命令如下:
sudo systemctl start mysqld.service
查看 MySQL 服务状态
systemctl status mysqld.service
输出如下: Active: active (running) 表示服务已经启动
● mysqld.service - MySQL database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2018-07-23 13:17:55 CST; 2s ago
Process: 13063 ExecStartPost=/usr/bin/mysqld-post (code=exited, status=0/SUCCESS)
Main PID: 13062 (mysqld)
Tasks: 38 (limit: 4915)
Memory: 307.2M
CGroup: /system.slice/mysqld.service
└─13062 /usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid
第六步:连接数据库
mysql -uroot -p
输入第三步: 密码即可连接成功
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>