linux rpm方式安裝mysql5.1


1、檢測系統是否已經安裝過mysql或其依賴,若已裝過要先將其刪除 

首先需要先停止mysqld服務,否則直接卸載rpm包后,重新安裝的mysql沒有初始密碼

[root@node2 mysql-5.7.26]# systemctl stop mysqld
[root@node2 mysql-5.7.26]# rpm -qa|grep mysql
mysql-community-libs-5.7.26-1.el7.x86_64
mysql-community-common-5.7.26-1.el7.x86_64
mysql-community-client-5.7.26-1.el7.x86_64
mysql-community-server-5.7.26-1.el7.x86_64
[root@node2 mysql-5.7.26]# rpm -e mysql-community-server-5.7.26-1.el7.x86_64
[root@node2 mysql-5.7.26]# rpm -e mysql-community-client-5.7.26-1.el7.x86_64
[root@node2 mysql-5.7.26]# rpm -e mysql-community-libs-5.7.26-1.el7.x86_64
[root@node2 mysql-5.7.26]# rpm -e mysql-community-common-5.7.26-1.el7.x86_64

卸載順序為server->client->libs->common

將剩余mysql目錄刪除干凈

[root@node2 mysql-5.7.26]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
[root@node2 mysql-5.7.26]# rm -rf var/lib/mysql
[root@node2 mysql-5.7.26]# rm -rf /usr/share/mysql
[root@node2 mysql-5.7.26]# rm -rf /var/log/mysqld.log 

 

2、下載rpm包 

mkdir  /usr/local/src/mysql-5.7.26
cd /usr/local/src/
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.26-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.26-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.26-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.26-1.el7.x86_64.rpm

3、安裝rpm包 

按照依賴順序依次安裝rpm包,依賴關系為common->libs->client->server

rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm

在安裝mysql-community-common-5.7.26-1.el7.x86_64.rpm ,可能會報錯:

file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.26-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.26-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64

提示是文件與mariadb-libs-1:5.5.60-1.el7_5.x86_64包里的沖突,卸載mariadb-libs-1:5.5.60-1.el7_5.x86_64即可

rpm -e mariadb-libs-1:5.5.60-1.el7_5.x86_64 --nodeps

 

4、驗證 

[root@node2 mysql-5.7.26]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@node2 mysql-5.7.26]# whereis my.cnf
my: /etc/my.cnf

 編輯my.cnf

[mysqld]
datadir=/home/mysql-5.7.26/data
user=mysql
symbolic-links=0
#server_id=71
#gtid_mode=on #開啟gtid模式
#enforce_gtid_consistency=on #強制gtid一致性
#log-bin=slave-71 #開啟二進制日志
#binlog_format=row
log-error=/home/mysql-5.7.26/log/mysqld.log

[mysqld_safe]
log-error=/home/mysql-5.7.26/log/mysqld.log

建立相關目錄

[root@localhost mysql-5.7.26]# mkdir /home/mysql-5.7.26/
[root@localhost mysql-5.7.26]# mkdir /home/mysql-5.7.26/log
[root@localhost mysql-5.7.26]# mkdir /home/mysql-5.7.26/data
[root@localhost mysql-5.7.26]# chown -R mysql:mysql /home/mysql-5.7.26/

 

5、第一次啟動mysql服務

systemctl start mysqld
[root@node2 src]# netstat -tunlp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      22905/mysqld 

查看3306端口,啟動成功,查看第一次運行mysql時,系統分配的root賬號臨時密碼,在日志文件里搜索'temporary password' 

[root@node3 mysql-5.7.26]# grep 'temporary password' /var/log/mysqld.log 
2019-05-03T07:30:18.845325Z 1 [Note] A temporary password is generated for root@localhost: _:fwrY:W-8;l

 6、利用密碼,啟動mysql客戶端並修改root賬號密碼 

[root@node3 mysql-5.7.26]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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>alter user 'root'@'localhost' identified by 'xxxxxxx';
Query OK, 0 rows affected (0.00 sec)

mysql> quit

  

7、利用新密碼重新登錄mysql 

[root@node3 mysql-5.7.26]# 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.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

 

 8、設置遠程連接權限

update user set host = ’%’ where user = ’root’;  //出現報錯可以忽略
grant all privileges  on *.* to root@'%' identified by "mypassword";
flush privileges;

9、查看結果

select host,user,password from user;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM