Linux Centos 7.4安裝mysql5.6

mysql5.6安裝手冊(cè)

linux系統(tǒng):Centos 7.4(使用lsb_release -a查看版本信息)
mysql版本:mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

下載地址

安裝步驟

0. 卸載老版本mysql

find / -name mysql

rm -rf 上邊查找到的路徑,多個(gè)路徑用空格隔開(kāi)

1. 下載、解壓

進(jìn)入安裝目錄

cd /usr/local

下載

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

解壓

tar -zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

2. 重命名、刪除安裝包

重命名

mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql

刪除安裝包

rm -f mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

3. 添加mysql用戶組和mysql用戶

檢查是否存在mysql用戶組

groups mysql

若有,則跳過(guò)


若無(wú),則添加

groupadd mysql
useradd -r -g mysql mysql

4. 進(jìn)入mysql目錄更改權(quán)限

cd mysql
chown -R mysql:mysql ./

5. 執(zhí)行安裝腳本

./scripts/mysql_install_db --user=mysql

遇到報(bào)錯(cuò)一
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper

解決方法:

yum -y install autoconf

遇到報(bào)錯(cuò)二
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解決方法:

yum -y install libaio-devel

安裝完之后修改當(dāng)前目錄擁有者為root用戶,修改data目錄擁有者為mysql

chown -R root:root ./
chown -R mysql:mysql data

mysql配置

6. 啟動(dòng)mysql

啟動(dòng)mysql

./support-files/mysql.server start

遇到報(bào)錯(cuò)一
./support-files/mysql.server: line 244: my_print_defaults: command not found
./support-files/mysql.server: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)

報(bào)錯(cuò)原因:support-files/mysql.server文件中的mysql的安裝目錄跟實(shí)際的安裝目錄不符,需要修改該文件。
解決方法:

vim support-files/mysql.server

進(jìn)入文件,修改以下內(nèi)容


繼續(xù)啟動(dòng)
遇到報(bào)錯(cuò)二
Starting MySQL.191129 15:40:20 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/var/lib/mysql/i[FAILED]w0bd0i0xw8wr8Z.pid).

解決方法:

mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb

終于啟動(dòng)成功。
查看serve運(yùn)行狀態(tài)

ps aux | grep mysql

7. 登錄mysql

./bin/mysql -uroot -p

或者使用

cd /usr/local/bin
./mysql -uroot -p 

首次登錄mysql輸入回車即可登錄

遇到報(bào)錯(cuò)一
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

解決方法:
查看/etc/my.cnf,發(fā)現(xiàn)socket=/var/lib/mysql/mysql.sock
執(zhí)行命令,將/tmp/目錄下的mysql.sock指向的連接是/var/lib/mysql/mysql.sock

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

8. 修改mysql密碼

mysql> use mysql;
mysql> update user set password = password('123456') where user = root;

查看用戶信息

mysql> select host, user, password from user;

9. 添加開(kāi)機(jī)啟動(dòng)

首先需要將support-files/mysql.server服務(wù)腳本復(fù)制到/etc/init.d/,并重命名為mysql

cp support-files/mysql.server /etc/init.d/mysql

通過(guò)chkconfig命令將mysqld服務(wù)加入到自啟動(dòng)服務(wù)項(xiàng)中

chkconfig --add mysql

查看是否添加成功

chkconfig --list mysql

如果看到mysql的服務(wù),并且3,4,5都是on的話則成功,如果是off,則執(zhí)行

chkconfig --level 345 mysql on

啟動(dòng)mysql:service mysql start
重啟mysql:service mysql restart
關(guān)閉mysql:service mysql stop
查看serve運(yùn)行狀態(tài):service mysql status

10. 把mysql客戶端放到默認(rèn)路徑

注意:建議使用軟鏈過(guò)去,不要直接包文件復(fù)制,便于系統(tǒng)安裝多個(gè)版本的mysql

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

11. 配置my.conf

vim my.conf

添加以下內(nèi)容

character-set-server=utf8
lower_case_table_names=1
max_allowed_packet=100M

配置好之后,重啟mysql服務(wù)

service mysql restart

問(wèn)題集合

  1. 遠(yuǎn)程連接mysql配置
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
  1. ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

修改my.cnf:vim /usr/local/mysql/my.cnf

[mysqld]
skip-grant-table

重啟mysql,輸入mysql

mysql> delete from user where user='';
mysql> flush privileges;

還原my.cnf的配置,重啟

參考文檔

  1. http://m.itdecent.cn/p/f4a98a905011
  2. https://www.cnblogs.com/hanmk/p/8513088.html
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容