在Linux 6.3安裝mysql5.7.16資料庫

eymit發表於2016-10-20
1、下載安裝包
http://dev.mysql.com/downloads/




2.檢查庫檔案是否存在,如有刪除。
[root@QuDaoMysql mysql]# rpm -qa | grep mysql
mysql-5.1.61-4.el6.x86_64
qt-mysql-4.6.2-24.el6.x86_64
mysql-server-5.1.61-4.el6.x86_64
mysql-libs-5.1.61-4.el6.x86_64
mysql-devel-5.1.61-4.el6.x86_64
[root@QuDaoMysql mysql]# 
[root@QuDaoMysql mysql]# rpm -e mysql-5.1.61-4.el6.x86_64 --nodeps
[root@QuDaoMysql mysql]# rpm -e qt-mysql-4.6.2-24.el6.x86_64 --nodeps
[root@QuDaoMysql mysql]# rpm -e mysql-server-5.1.61-4.el6.x86_64 --nodeps
[root@QuDaoMysql mysql]# rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps
[root@QuDaoMysql mysql]# rpm -e mysql-devel-5.1.61-4.el6.x86_64 --nodeps
[root@QuDaoMysql mysql]# 


3.檢查mysql組和使用者是否存在,如無建立。
[root@QuDaoMysql mysql]# cat /etc/group | grep mysql
mysql:x:27:
[root@QuDaoMysql mysql]# cat /etc/passwd | grep mysql
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash


注意安裝順序
rpm -ivh  mysql-community-common-5.7.16-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.16-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.16-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.16-1.el6.x86_64.rpm


[root@QuDaoMysql _rpminstall]# rpm -ivh  mysql-community-common-5.7.16-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [100%]
[root@QuDaoMysql _rpminstall]# rpm -ivh mysql-community-libs-5.7.16-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-libs   ########################################### [100%]
[root@QuDaoMysql _rpminstall]# rpm -ivh mysql-community-client-5.7.16-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-client ########################################### [100%]
[root@QuDaoMysql _rpminstall]# rpm -ivh mysql-community-server-5.7.16-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-server warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
########################################### [100%]
[root@QuDaoMysql _rpminstall]# 


安裝過程中會生成my.cnf,手動把原來的覆蓋


[root@QuDaoMysql _rpminstall]# cp /etc/my.cnf.rpmnew  /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@QuDaoMysql _rpminstall]# 




4、啟動mysql 


[root@QuDaoMysql _rpminstall]# /etc/rc.d/init.d/mysqld start
Initializing MySQL database:  [  OK  ]
Installing validate password plugin:  [  OK  ]
Starting mysqld:  [  OK  ]
[root@QuDaoMysql _rpminstall]# 






5、mysql5.7 開始有預設的密碼
[root@QuDaoMysql _rpminstall]# cat /var/log/mysqld.log|grep 'temporary password'
2016-10-20T03:07:36.130787Z 1 [Note] A temporary password is generated for root@localhost: EGlLlD,dg2qe
[root@QuDaoMysql _rpminstall]# 


初始密碼為  EGlLlD,dg2qe


6、登入
輸入密碼,重置密碼
[root@QuDaoMysql _rpminstall]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16


Copyright (c) 2000, 2016, 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> 
mysql>  SET PASSWORD = PASSWORD('xxxxxx');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> 
mysql>  SET PASSWORD = PASSWORD('xxxxxxx');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 








7、授權遠端連線
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxx' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> FLUSH   PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)


mysql> 
mysql> 




說明:如果遠端連線不上,關閉防火牆。




8.配置mysql自動啟動  
# chkconfig --level 345 mysqld on   ---設定MySQL在345等級自動啟動  






9.修改預設目錄
關閉資料庫
[root@QuDaoMysql prlife]# service mysqld  stop
Stopping mysqld:  [  OK  ]
[root@QuDaoMysql prlife]# cd /var/lib/




拷貝必須使用-a,否則許可權會亂掉
[root@QuDaoMysql lib]# cp -a mysql   /prlife/




修改第一個檔案
修改/etc/my.cnf,修改前需要進行備份


#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/prlife/mysql/data
socket=/prlife/mysql/data/mysql.sock




再增加以下幾個引數,否則會報錯
[mysql.server]
user=mysql
basedir=/prlife/mysql/data/mysql
[client]
socket=/prlife/mysql/data/mysql.sock








修改第二個檔案:mysqld


修改之前進行備份
[root@QuDaoMysql mysql]# cp /etc/init.d/mysqld /etc/init.d/mysqld_bak
[root@QuDaoMysql mysql]# vi /etc/init.d/mysqld
替換所有 /var/lib/mysql為/prlife/mysql/data




修改第三個檔案
修改之前先備份 
cp  /usr/bin/mysqld_safe  /usr/bin/mysqld_safebak
vi /usr/bin/mysqld_safe
替換所有 /var/lib/mysql為 /prlife/mysql/data




(4)建立一個mysql.sock的連結


[root@QuDaoMysql lib]# mkdir -p /var/lib/mysql/
[root@QuDaoMysql lib]# chown -R mysql.mysql  /var/lib/mysql
[root@QuDaoMysql lib]# ln -s  /prlife/mysql/data/mysql.sock  /var/lib/mysql/mysql.sock






重啟資料庫




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21605631/viewspace-2126831/,如需轉載,請註明出處,否則將追究法律責任。

相關文章