CentOS-7.5 安裝 社區版 MySQL-5.7

一、實驗環境node

服務器類型:VMware虛擬機
服務器操做系統:CentOS-7.5
服務器名稱:CentOS-1
服務器IP:192.168.218.128
防火牆+selinux均已關閉
網絡連通情況:服務器能夠上外網mysql

二、MySQL-5.7 安裝源的下載linux

1)先卸載系統自帶的mariadb
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# rpm -qa mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# rpm -qa mariadb

[root@CentOS-1 ~]# sql

2)下載並安裝mysql-5.7的安裝源
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm #安裝mysql-5.7的安裝源數據庫

[root@CentOS-1 ~]# ll /etc/yum.repos.d/ | grep 'mysql-community*'
CentOS-7.5 安裝 社區版 MySQL-5.7
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# yum list mysql-community-server
CentOS-7.5 安裝 社區版 MySQL-5.7vim

三、刪除Linux系統原來自帶的 my.cnf 文件(若是存在的話)安全

[root@CentOS-1 ~]# rm -rf /etc/my.cnf
[root@CentOS-1 ~]# 服務器

四、安裝 MySQL-5.7
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# yum -y install mysql-community-server #安裝mysql
[root@CentOS-1 ~]# rpm -q mysql-community-server
mysql-community-server-5.7.29-1.el7.x86_64
[root@CentOS-1 ~]# 網絡

五、啓動MySQL-5.7
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# systemctl start mysqld.service #啓動mysql
[root@CentOS-1 ~]# systemctl enable mysqld.service #設置mysql服務爲自啓動
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# lsof -i:3306
CentOS-7.5 安裝 社區版 MySQL-5.7
[root@CentOS-1 ~]# ide

六、修改配置文件
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# mkdir /var/lib/mysql/binary_log #建立用於存放binlog日誌的目錄'binary_log'
[root@CentOS-1 ~]# ls /var/lib/mysql/binary_log
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# ll /var/lib/mysql | grep 'binary_log' #查看'binary_log'目錄的權限
CentOS-7.5 安裝 社區版 MySQL-5.7
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# chown -R mysql.mysql /var/lib/mysql/binary_log #修改該目錄權限
[root@CentOS-1 ~]# ll /var/lib/mysql | grep 'binary_log'
CentOS-7.5 安裝 社區版 MySQL-5.7

[root@CentOS-1 ~]# vim /etc/my.cnf #編輯修改mysql服務器的配置文件
說明:由於後期要配置主從同步,因此配置文件中設置server-id,以及binlog存儲文件以master_a-binlog開頭(master_a表示第一個主服務器)
CentOS-7.5 安裝 社區版 MySQL-5.7

[root@CentOS-1 ~]# cat /etc/my.cnf #查看修改後的配置文件
CentOS-7.5 安裝 社區版 MySQL-5.7
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# systemctl restart mysqld.service #重啓mysql服務,使配置生效
[root@CentOS-1 ~]#
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# ll /var/lib/mysql/binary_log/ #查看此時是否生成了binlog文件
CentOS-7.5 安裝 社區版 MySQL-5.7

七、MySQL登陸測試
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# grep 'temporary' /var/log/mysqld.log #查看系統分配的mysql臨時登陸密碼
CentOS-7.5 安裝 社區版 MySQL-5.7

[root@CentOS-1 ~]# mysql -uroot -p'piDr2,8x#W6S' #使用臨時密碼登陸mysql並作查詢操做,發現查詢失敗
CentOS-7.5 安裝 社區版 MySQL-5.7

[root@CentOS-1 ~]#
[root@CentOS-1 ~]# mysql -uroot -p'piDr2,8x#W6S' #再次登陸mysql,根據錯誤提示進行排錯
mysql>
mysql> show databases; #查看錯誤提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@123'; #根據錯誤提示進行排錯
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> flush privileges; #刷新權限
Query OK, 0 rows affected (0.00 sec)

mysql>
CentOS-7.5 安裝 社區版 MySQL-5.7

八、使用安全配置嚮導設置MySQL(MySQL初始化)
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# mysql_secure_installation #安全配置嚮導
Securing the MySQL server deployment.

Enter password for user root: #輸入root用戶密碼'Mysql@123'
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 #預計密碼強度爲100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y #更改root用戶密碼(是或者否)

New password: #輸入新root密碼,此處新密碼設置爲「Mysql.2020」

Re-enter new password: #再次輸入新root密碼「Mysql.2020」

Estimated strength of the password: 100 #預計密碼強度爲100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y #您是否要繼續使用提供的root密碼(是或者否)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #是否刪除匿名用戶
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #禁止root用戶從遠程登陸mysql服務器
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #是否刪除測試數據庫

  • Dropping test database...
    Success.

  • Removing privileges on test database...
    Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #如今從新加載受權表
Success.

All done!
[root@CentOS-1 ~]#

九、MySQL登陸
[root@CentOS-1 ~]#
[root@CentOS-1 ~]# mysql -uroot -p'Mysql.2020'
CentOS-7.5 安裝 社區版 MySQL-5.7

相關文章
相關標籤/搜索