- 1.从官网下载yum源rpm包并安装
https://dev.mysql.com/downloads/repo/yum/
下载rpm包
# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装mysql源
# yum -y install mysql57-community-release-el7-11.noarch.rpm
检查mysql源是否安装成功
# yum repolist enabled | grep "mysql.*-community.*"
查看一下mysql-community.repo内容,安装5.7版本,所以mysql57-community的 enabled=1
# vim /etc/yum.repos.d/mysql-community.repo
- 2.安装mysql
# yum -y install mysql-community-server
- 3.启动mysql服务以及修改配置
# systemctl start mysqld
查看启动状态
# systemctl status mysqld
设置开机启动
# systemctl enable mysqld
# systemctl daemon-reload
安装完成后,在 /var/log/mysqld.log 文件中会给root生成一个密码,找到root密码之后进行修改
# vim /var/log/mysqld.log password=wo9RtLyp&/U-
设置root新密码
mysql初始密码规则
mysql> show variables like '%password%'; +---------------------------------------+--------+ | Variable_name | Value | +---------------------------------------+--------+ | default_password_lifetime | 0 | | disconnect_on_expired_password | ON | | log_builtin_as_identified_by_password | OFF | | mysql_native_password_proxy_users | OFF | | old_passwords | 0 | | report_password | | | sha256_password_proxy_users | OFF | | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +---------------------------------------+--------+
mysql> set password for 'root'@'localhost'=password('Captain#007');
也可以修改密码规则,编辑 /etc/my.cnf文件,将下面内容添加到文件中,然后重启服务
validate_password_policy=0 validate_password_length=4 validate_password_mixed_case_count=0 validate_password_number_count=0
# systemctl restart mysqld
把所有数据库中的所有表的权限赋给所有ip地址的root用户
mysql> grant all privileges on *.* to root@'%'identified by 'Captain#007';
或者新建一个用户
mysql>create user 'mysql'@'%' identified by 'mysql';
修改字符集
编辑 /etc/my.cnf 添加如下内容到文件中
character_set_server=utf8
再次查看字符集编码:
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)
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid