第一步、下載MySQL 安裝包:
[root@localhost local]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安裝mysql 安裝源:
[root@localhost local]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
第二步,在線安裝MySQL
[root@localhost local]# yum -y install mysql-community-server
等待時(shí)間比較久 note:如果這里發(fā)生錯(cuò)誤centos7.8安裝mysql5.7時(shí)Error: Unable to find a match: mysql-community-server
解決:
先執(zhí)行:yum module disable mysql
再執(zhí)行:yum -y install mysql-community-server
第三步、啟動(dòng)mysql 服務(wù)
[root@localhost local]# systemctl start mysqld
第四步,設(shè)置開機(jī)啟動(dòng)
[root@localhost local]# systemctl enable mysqld
[root@localhost local]# systemctl daemon-reload
第五步,修改root登錄密碼
mysql安裝完成之后,會(huì)在/var/log/mysqld.log文件中給root生成了一個(gè)臨時(shí)的默認(rèn)密碼。
[root@localhost local]# vim /var/log/mysqld.log

image.png
記住初始密碼:
修改root 密碼
[root@localhost local]# mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'daasan7ujm^YHN';
Query OK, 0 rows affected (0.00 sec)
# 設(shè)置遠(yuǎn)程登錄
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'daasan7ujm^YHN' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
第六步,退出
mysql> exit
第七步,防火墻開放3306端口
自行百度
第八步,重啟防火墻。
[root@localhost sysconfig]# service iptables restart
第九步,配置mysql默認(rèn)編碼為utf-8
[root@localhost sysconfig]# vim /etc/my.cnf
添加如下代碼
character_set_server=utf8
init_connect='SET NAMES utf8'
:wq 保存退出
第十步,重啟MySQL
[root@localhost data]# systemctl restart mysqld
第十一步, root 用戶登錄查看編碼
[root@localhost sysconfig]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
done!