1. 下载 yum 源文件 mysql80-community-release-el7-2.noarch.rpm
https://dev.mysql.com/downloads/repo/yum/
2. 安装源
sudo rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
3. 查看安装结果
yum repolist all | grep mysql
4. 将默认版本改为 5.7
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
5. 查看修改结果
yum repolist all | grep mysql
6. 安装
sudo yum install mysql-community-server.x86_64 (2min)
7. 启动并查看状态
sudo systemctl start mysqld.service
sudo systemctl status mysqld.service
8. 获得初始密码
sudo grep 'temporary password' /var/log/mysqld.log
9. 使用初始密码登陆 mysql
mysql -u root -p
10. 修改密码(总长度大于8,必须:一个小写字母,一个大写字母,一个数字,一个特殊符号)例如,
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ABC12345q!';
11. 修改编码方式到 utf8
默认情况下,mysql5.7 的编码方式如下,
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
在 CentOS7 下,mysql 的配置文件是 /etc/my.cnf,打开在最后加上一句,
character-set-server=utf8
然后重启 mysql 服务,
$ sudo systemctl restart mysqld
再次查看,
mysql> show variables like 'character_set_%'; +--------------------------+----------------------------+ | 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)
其它高级设置参考:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
12. 使用 mycli 自动补全 (only support python3)
默认 mysql 命令行登陆后,输入命令不会提示及自动补全,非常麻烦,通过使用 mycli 自动补全会方便很多。
安装如下,
$ sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ mycli
使用 mycli 启动数据库连接,
$ mycli -h 127.0.0.1 -u root -p ******** ( here your MySQL password)
Ubuntu 18.04 下的安装方法如下: https://www.cnblogs.com/gaowengang/p/10816537.html
13. 安装 mysql-workbench
官网下载安装包 https://dev.mysql.com/downloads/workbench/
$ sudo rpm -iv mysql-workbench-community-8.0.22-1.el7.x86_64.rpm