1、配置YUM源
下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查MySQL源是否安装成功
shell> yum repolist enabled | grep “mysql.-community.”
2、安装MySQL
shell> yum install mysql-community-server
3、启动MySQL服务
shell> systemctl start mysqld
查看MySQL的启动状态
shell> systemctl status mysqld
4、开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
5、修改root本地登录密码
grep ‘temporary password’ /var/log/mysqld.log
mysql -uroot –p+生产注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
第一次通过命令行窗口登录MySQL5.7时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- 打开etc/my.cnf文件,在文件的最后添加一行“skip-grant-tables”,保存并关闭文件。(Win10默认安装,my.ini在C:\ProgramData\MySQL\MySQL Server 5.7)
- 重启MySQL57和MySQL Router服务。
- 通过命令行窗口进入MySQL的bin目录,输入“mysql -u root -p”(不输入密码),回车即可进入数据库。(Win10默认安装,bin目录为:C:\Program Files\MySQL\MySQL Server 5.7\bin)
- 执行“use mysql”,使用MySQL数据库。
- 执行“ update user set authentication_string=PASSWORD("此处请输入您要设定的密码") where user='root';” 注意密码格式:至少包含一个大写字母、一个小写字母、一个特殊符号、一个数字,密码长度至少为8个字符。
- 打开MySQL目录下的my.ini文件,删除最后一行的“skip-grant-tables”,保存并关闭文件。
- 重启MySQL57和MySQL Router服务。
- 在命令行中输入“mysql -u root -p”,回车,然后输入您设置的密码即可成功连接数据库。
6、添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,
mysql> GRANT ALL PRIVILEGES ON . TO ‘*’@’ localhost’ IDENTIFIED BY ’ MyNewPass4!’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO ‘*’@’ Spark’ IDENTIFIED BY ’ MyNewPass4!’ WITH GRANT OPTION;
7、配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect=’SET NAMES utf8’
常见问题:
1.ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this ..
解决:首先修改用户的密码。(下面两个命令一个意思,任选其一即可)
alter user 'root'@'localhost' identified by 'youpassword';
set password=password("youpassword");
然后在刷新权限。
flush privileges;
2.MySQ修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决:
- set global validate_password_policy=0;
- set global validate_password_mixed_case_count=0;
- set global validate_password_number_count=3;
- set global validate_password_special_char_count=0;
- set global validate_password_length=3;
- 解决 ok;
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
转发自:https://www.centoschina.cn/server/sql/mysql/8661.html