下载地址MySQL5.7.27参考
https://dev.mysql.com/downloads/file/?id=487589
安装MySQL5.7.27参考地址
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
下载安装
- 查看需要安装mysql的服务器版本并下载mysql安装包
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-862.3.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Mon May 21 23:36:36 UTC 2018
这里我用的服务器是Red Hat的x86_64位的Linux,所以需要下载该Linux版本对应的mysql安装包
[root@localhost mysql]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
- 安装标准的mysql
[root@localhost mysql]# tar -xvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
mysql-community-libs-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.27-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
mysql-community-devel-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.27-1.el7.x86_64.rpm
mysql-community-common-5.7.27-1.el7.x86_64.rpm
mysql-community-client-5.7.27-1.el7.x86_64.rpm
mysql-community-server-5.7.27-1.el7.x86_64.rpm
mysql-community-test-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-5.7.27-1.el7.x86_64.rpm
[root@localhost mysql]# sudo yum install mysql-community-{server,client,common,libs}-*
安装成功可以看到
Installed:
mysql-community-client.x86_64 0:5.7.27-1.el7
mysql-community-common.x86_64 0:5.7.27-1.el7
mysql-community-libs.x86_64 0:5.7.27-1.el7
mysql-community-libs-compat.x86_64 0:5.7.27-1.el7
mysql-community-server.x86_64 0:5.7.27-1.el7
Complete!
- 启动mysql
[root@localhost mysql]# sudo service mysqld start
- 设置超级用户密码
4.1 关掉mysql
[root@localhost mysql]# sudo service mysqld stop
4.2 修改/etc/my.cnf,打开my.cnf文件,在mysqld下面添加skip-grant-tables,保存退出。
[root@localhost mysql]# vim /etc/my.cnf
# innodb_buffer_pool_size = 128M
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
skip-grant-tables
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
4.3 启动mysql
[root@localhost mysql]# sudo service mysqld start
4.4 进入mysql数据库,修改root密码为Frank@668
[root@localhost mysql]# mysql -u root -p
Enter password: #直接点击确认
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password('Frank@668') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
Bye
4.5 修改/etc/my.cnf ,删掉skip-grant-tables,重新启动mysql
[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# sudo service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
4.6 重新使用root账号进入mysql,使用ALTER 重置密码
[root@localhost mysql]# mysql -u root -p
Enter password: #输入刚刚设置的密码Frank@668
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Frank@668';
Query OK, 0 rows affected (0.00 sec)
- 远程链接
5.1 赋予root权限
[root@localhost mysql]# mysql -u root -p
Enter password: #输入刚刚设置的密码Frank@668
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Frank@668' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
5.2 开启3306端口
[root@localhost mysql]# systemctl start firewalld
[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost mysql]# firewall-cmd --reload
5.3 远程链接
开源一个微信公众号留言小程序,欢迎大家Fork:
https://github.com/fuxingkai/LMsg