0x00 前言
心血来潮,学习sql和mysql,光说不练假把式,就在自己的笔记本上面折腾起了mysql的安装环境,笔记本是arch
0x01 安装mysql
$ sudo pacman -S mysql
返回:
warning: mysql-8.0.19-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
Packages (1) mysql-8.0.19-1
Total Installed Size: 194.42 MiB
Net Upgrade Size: 0.00 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring [######################] 100%
(1/1) checking package integrity [######################] 100%
(1/1) loading package files [######################] 100%
(1/1) checking for file conflicts [######################] 100%
(1/1) checking available disk space [######################] 100%
:: Processing package changes...
(1/1) reinstalling mysql [######################] 100%
:: Running post-transaction hooks...
(1/3) Reloading system manager configuration...
(2/3) Creating temporary files...
error: command failed to execute correctly
(3/3) Arming ConditionNeedsUpdate...
乍一看没什么问题,但是,真正的安装完成是这样的:
正在解决依赖关系...
正在查找软件包冲突...
软件包 (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...
没错,少了一截这个:
:: 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
:: 正在运行事务后钩子函数...
我当时没发现,直到执行初始化的时候,开始报警。。。
0x02 初始化
初始化命令
$ sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
正确的应该是这个样子的,最后一行是它创建的用户名root@localhost
和密码gyLkhoMTo2.w
,链接同上:
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
而我的是这个样子的:
mysqld: error while loading shared libraries: libicuuc.so.65: cannot open shared object file: No such file or directory
问题的原因以及解决,如这篇文章所述,Manjaro安装mysql提示loading libicuuc.so.65错误
提示这一错误的原因是
Manjaro
系统中自带的libicu
版本是64.2
,而Mysql
默认安装的是8
版本需要libicuuc65
版本。这时候去github下载并编译安装进系统,并软链接到/usr/lib/
目录下即可
# 安装libicuuc
$ wget https://github.com/unicode-org/icu/releases/download/release-65-rc/icu4c-65rc-src.tgz
$ tar -zxvf icu4c-65rc-src.tgz
$ cd icu/source
$ ./configure
$ make
$ sudo make install
# 创建软连接
## icu4c-65rc的默认安装位置为/usr/local/lib
$ sudo ln -s /usr/local/lib/libicuuc.so.65 /usr/lib/libicuuc.so.65
$ sudo ln -s /usr/local/lib/libicui18n.so.65 /usr/lib/libicui18n.so.65
$ sudo ln -s /usr/local/lib/libicudata.so.65 /usr/lib/libicudata.so.65
好的,跟我的问题一毛一样,照搬照抄,继续执行初始化命令:
$ sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
结果返回:
mysqld: error while loading shared libraries: libevent_core-2.1.so.7: cannot open shared object file: No such file or directory
我的意大利炮呢!?继续搞,尝试下安装libevent
这个包看看能不能解决:
$ sudo pacman -S libevent
继续执行初始化命令:
$ sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
结果返回:
mysqld: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by mysqld)
搞吧,都搞了一半了,半途而废不是我的性格,
网络上查到的原因是系统自带的lib
库版本太低了,查看命令如下:
$ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
$ ls -alh /usr/lib/libstdc++.so.6 # 查看libstdc++.so.6指向哪
lrwxrwxrwx 1 root root 19 Feb 20 20:29 /usr/lib/libstdc++.so.6 -> libstdc++.so.6.0.25
返回,最高3.4.25
,很尴尬,mysql
需要的是3.4.26
:
GLIBCXX_3.4
GLIBCXX_3.4.1
...
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
想要提高
lib
库,需要提高gcc
的版本,我的是:
$ gcc --version
gcc (GCC) 8.2.1 20181127
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
接下来是升级GCC的艰难路程
- 最终的解决思路是:
sudo pacman -S gcc
- 教程传送门 — > Linux安装GCC 9.2.0
以下为gcc安装, 作为扩展知识,源码安装我失败了,卡在了make
其中,当安装依赖无反应时,即:./contrib/download_prerequisites
没有任何反馈,可以考虑手动下载依赖包到GCC源码根目录。如下:
$ wget http://ftp.gnu.org/pub/gnu/gmp/gmp-6.1.0.tar.bz2
$ wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.bz2
$ wget http://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
$ wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
然后:
...
libtool: link: ranlib .libs/libitm.a
libtool: link: ( cd ".libs" && rm -f "libitm.la" && ln -s "../libitm.la" "libitm.la" )
make[4]: Leaving directory '/home/lebhoryi/Software/gcc-9.2.0/gcc-build/x86_64-pc-linux-gnu/libitm'
make[3]: Leaving directory '/home/lebhoryi/Software/gcc-9.2.0/gcc-build/x86_64-pc-linux-gnu/libitm'
make[2]: Leaving directory '/home/lebhoryi/Software/gcc-9.2.0/gcc-build/x86_64-pc-linux-gnu/libitm'
make[1]: Leaving directory '/home/lebhoryi/Software/gcc-9.2.0/gcc-build'
make: *** [Makefile:1004: all] Error 2
王德发?! 我体内的洪荒之力快控制不住了
最后的最后,升级gcc
到9.2的命令,简单但是有效:
$ sudo pacman -Sy gcc
$ gcc --version
gcc (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
解决GLIBCXX
低版本问题,继续初始化
$ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
$ sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
2020-02-21T11:37:28.689970Z 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.
2020-02-21T11:37:28.690046Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 1479
2020-02-21T11:37:28.694041Z 0 [ERROR] [MY-010124] [Server] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
2020-02-21T11:37:28.694054Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-02-21T11:37:28.694123Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-02-21T11:37:28.694270Z 0 [System] [MY-010910] [Server] /usr/bin/mysqld: Shutdown complete (mysqld 8.0.19) Source distribution.
- 黑人问号.jpg
经过查询多方资料,mysql
的初始化没有问题,是我arch
中少了这么个mysql
用户。。。问题在这一句
2020-02-21T11:37:28.694041Z 0 [ERROR] [MY-010124] [Server] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
解决MySQL报错:Fatal error: Can’t change to run as user ‘mysql’;Please check that the user exists!
$ sudo useradd mysql
# 初始化成功,账号是root@localhost,密码是aEHI7*?3RU0l,每个人的账号密码不一样,以输出为准
$ sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
2020-02-21T12:10:08.438121Z 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.
2020-02-21T12:10:08.438192Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 9852
2020-02-21T12:10:10.297971Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: aEHI7*?3RU0l
0x03 开机自启
$ sudo systemctl enable mysqld.service
0x04 启动 MySQL 服务
$ sudo systemctl start mysqld.service
# 报错
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
用systemctl status mysqld.service
和journalctl -xe
查不出任何信息,经上网查证,CentOS 7下MySQL服务启动失败的解决思路,解决方式如下:
$ sudo mkdir -p /var/run/mysqld/
$ sudo chown -R mysql:mysql /var/run/mysqld/
继续运行,成功
$ sudo systemctl start mysqld.service
# 查看 MySQL 服务状态,激活中
$ sudo systemctl status mysqld.service
[sudo] password for lebhoryi:
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: di>
Active: active (running) since Fri 2020-02-21 20:36:31 CST; 6min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 24653 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCC>
Main PID: 24674 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 4915)
Memory: 403.0M
CGroup: /system.slice/mysqld.service
└─24674 /usr/bin/mysqld
Feb 21 20:36:31 archlinux systemd[1]: Starting MySQL Server...
Feb 21 20:36:31 archlinux mysqld[24674]: 2020-02-21T12:36:31.524833Z 0 [Warning] [MY->
Feb 21 20:36:31 archlinux mysqld[24674]: 2020-02-21T12:36:31.524921Z 0 [System] [MY-0>
Feb 21 20:36:31 archlinux mysqld[24674]: 2020-02-21T12:36:31.893717Z 0 [Warning] [MY->
Feb 21 20:36:31 archlinux mysqld[24674]: 2020-02-21T12:36:31.919452Z 0 [System] [MY-0>
Feb 21 20:36:31 archlinux systemd[1]: Started MySQL Server.
Feb 21 20:36:32 archlinux mysqld[24674]: 2020-02-21T12:36:32.093950Z 0 [System] [MY-0>
lines 1-20/20 (END)
0x05 连接mysql
$ mysql -u root -p
# 输入你上面的密码,成功
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
# 使用临时用户更改上面的复杂的密码,大功告成,畅游吧,骚年
MySQL [(none)]> ALTER user 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.011 sec)