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)