安裝前准備:
現在Arch官方源是MariaDB,所以得從mysql官網下載,地址:https://www.mysql.com/downloads/
選擇一個合適的版本下載:
下載下來先將壓縮文件解壓到/usr/local,將長長的文件夾名稱改為mysql(方便)
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
安裝步驟:
1、創建用戶組:
groupadd mysql //創建用戶組mysql useradd -r -g mysql mysql //-r參數表示mysql用戶是系統用戶,不可用於登錄系統,創建用戶mysql並將其添加到用戶組mysql中 chown -R mysql mysql/ chgrp -R mysql mysql/
2、創建配置文件
vim /etc/my.cnf
在該文件里面添加如下內容:
[client] default-character-set=utf8 port = 3306 socket = /tmp/mysql.sock [mysql] default-character-set=utf8 port = 3306 socket = /tmp/mysql.sock [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid #不區分大小寫 lower_case_table_names = 1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION max_connections=5000
default-time_zone = '+8:00' # skip-grant-tables
3、初始化數據庫
用下面語句初始化數據庫:
bin/mysqld --initialize --user=mysql
執行的時候竟然出錯了,報錯如下:
libnuma.so.1: cannot open shared object file
缺少libnuma.so,安裝numactl就可以解決這個問題:
sudo pacman -S numactl
再執行一次,OK了,安裝順利。
下面開啟mysql服務並登陸:
/usr/local/mysql/support-files/mysql.server start
mysql -u root -p
不料這時又出現了錯誤(盜個圖,當時我未截圖):
缺少libncurses.so.5,在arch里是ncurses5-compat-libs,同樣進行安裝:
sudo pacman -S ncurses5-compat-libs
安裝之后再次登陸,結果發現了新的問題:
Access denied for user 'root'@'localhost' (using password:YES)
解決這個問題需要修改mysql登錄設置。
4、修改MySQL登錄設置
(1)編輯/etc目錄下面的my.cnf文件:
vim /etc/my.cnf
(2)在末尾追加語句:
skip-grant-tables
(3)重新啟動mysql:
/usr/local/mysql/support-files/mysql.server restart
(4)登陸mysql,按照如下步驟進行修改:
# /usr/local/mysql/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.56 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> USE mysql ; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET authentication_string = password ( 'new-password' ) WHERE User = 'root' ; Query OK, 0 rows affected (0.00 sec) Rows matched: 2 Changed: 0 Warnings: 0 mysql> flush privileges ; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye
(5)將/etc/my.cnf中的skip-grant-tables刪除並保存退出,重啟mysqld即可。
5、設置開機自啟
這個目前還在摸索中。。。
6、出現的問題
(1)今天登陸mysql,出現了一個問題:
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysqld.pid).
嘗試遍很多方法都沒能解決,最后在這篇博客里面找到了答案:
https://www.interserver.net/tips/kb/mysql-error-server-quit-without-updating-pid-file/
我這里是將my.cnf改為my.cnf.bak就OK了,究竟是什么原因導致的,還需要進一步研究
(2)忘記root密碼
把root密碼忘記了,無法登陸mysql,起初以為更改密碼很簡單,但過程中還是遇到了一些問題:
首先要停止mysql服務:
/usr/local/mysql/support-files/mysql.server stop
用以下命令啟動MySQL,以不檢查權限的方式啟動:
mysqld --skip-grant-tables &
但就是執行完這部后出了問題,出錯如下:
InnoDB: The innodb_system data file 'ibdata1' must be writable [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable [ERROR] InnoDB: Plugin initialization aborted with error Generic error [ERROR] Plugin 'InnoDB' init function returned error. [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. [ERROR] Failed to initialize builtin plugins. [ERROR] Aborting
看着出錯提示應該是權限問題,可以更改權限:
sudo chmod -R 777 mysql/*
在執行mysqld --skip-grant-tables & 就沒有再出現錯誤
剩下的步驟參考上面修改mysql配置就可以