下载mysql的rpm文件
# wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
如果没有wget命令,可参考 安装wget命令
升级rpm包
# rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
说明:本次使用root账户安装,如果是非root账户,命令开头需要添加sudo,下同。
查看mysql相关包
# yum repolist all | grep mysql
输出如下:
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 131
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 100
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 384
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
说明:安装mysql community server时,默认安装5.7版本(enabled的版本)
安装mysql服务
# yum install -y mysql-community-server
如果安装出现如下警告
原因是Mysql的GPG升级了,需要重新获取,获取命令如下
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
启动mysql服务
# systemctl start mysqld
查看默认的随机密码
# grep 'temporary password' /var/log/mysqld.log
输出如下:
2019-11-04T16:40:09.957827Z 1 [Note] A temporary password is generated for root@localhost: xGgd&oRNO8W.
xGgd&oRNO8W. 为随机密码
修改密码
进入mysql命令行
# mysql -uroot -p
输入上一步得到的随机密码,进入mysql命令行
mysql> SET PASSWORD = PASSWORD('12345678');
注意:
1.mysql> 为命令提示符,不用输入;
2.12345678是设置的密码,自行更改,密码至少为8个字符;
3.如果提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,说明密码不满足安全要求,需要增加密码复杂度。
允许远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
注意:'12345678'为上一步设置的密码,注意按实际修改。
刷新配置
mysql> flush privileges;
退出mysql命令行
按住Ctrl + z或键入quit;退出mysql命令行
相关设置
设置编码/sql_mode/时区
# nano /etc/my.cnf
末尾添加如下内容:
character-set-server=utf8
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default-time_zone = '+8:00'
重启mysql服务
# systemctl restart mysqld
设置开机启动mysql
# systemctl enable mysqld
重新加载进程
# systemctl daemon-reload
mysql安装目录介绍:
Files or Resources | Location |
Client programs and scripts | /usr/bin |
mysqld server | /usr/sbin |
Configuration file | /etc/my.cnf |
Data directory | /var/lib/mysql |
Error log file | For RHEL, Oracle Linux, CentOS or Fedora platforms: /var/log/mysqld.log For SLES: /var/log/mysql/mysqld.log |
Value of secure_file_priv | /var/lib/mysql-files |
System V init script | For RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqld For SLES: /etc/init.d/mysql |
Systemd service | For RHEL, Oracle Linux, CentOS or Fedora platforms: mysqld For SLES: mysql |
Pid file | /var/run/mysql/mysqld.pid |
Socket | /var/lib/mysql/mysql.sock |
Keyring directory | /var/lib/mysql-keyring |
Unix manual pages | /usr/share/man |
Include (header) files | /usr/include/mysql |
Libraries | /usr/lib/mysql |
Miscellaneous support files (for example, error messages, and character set files) | /usr/share/mysql |
至此完成mysql的安装,接下来可以测试用navicat等工具连接到数据库。
完成! enjoy it!