【Centos7 在线安装MySQL5.7】
第一步:下载MySQL安装包
[root@iZ2zee8932c78gnxtonmzqZ ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
第二步:安装MySQL安装源
[root@iZ2zee8932c78gnxtonmzqZ ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
第三步:在线安装MySQL5.7
[root@iZ2zee8932c78gnxtonmzqZ ~]# yum -y install mysql-community-server
此步等待时间可能会很久,取决于自己网络环境
第四步:启动MySQL
[root@iZ2zee8932c78gnxtonmzqZ ~]# systemctl start mysqld
第五步:设置开机自启动
[root@iZ2zee8932c78gnxtonmzqZ ~]# systemctl enable mysqld
[root@iZ2zee8932c78gnxtonmzqZ ~]# systemctl daemon-reload
第六步:修改root登录密码
mysql安装完成之后,就会在/var/log/mysqld.log文件中给root生成了一个临时密码
[root@iZ2zee8932c78gnxtonmzqZ ~]# vim /var/log/mysqld.log
登录mysql修改root密码
[root@iZ2zee8932c78gnxtonmzqZ ~]# mysql -u root -p
# 修改MySQL默认密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wvyao007^';
# 设置MySQL允许远程连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Wvyao007^' WITH GRANT OPTION;
第七步:退出MySQL
mysql> exit
第八步:开放防火墙3306端口
查看防火墙状态
# 结果为:running或not running
[root@iZ2zee8932c78gnxtonmzqZ /]# firewall-cmd --state
开放3306端口
[root@iZ2zee8932c78gnxtonmzqZ /]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
[root@iZ2zee8932c78gnxtonmzqZ /]# firewall-cmd --reload
第九步:配置MySQL默认编码为utf-8
[root@iZ2zee8932c78gnxtonmzqZ /]# vim /etc/my.cnf
character_set_server=utf8
init_connect='SET NAMES utf8'
第十步:重启MySQL服务
[root@iZ2zee8932c78gnxtonmzqZ /]# systemctl restart mysqld
第十一步: 登录MySQL root用户查看默认编码
[root@iZ2zee8932c78gnxtonmzqZ /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.7.31 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.01 sec)
mysql>