# yum install

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

yum install -y mysql-community-server

  • 配置文件

vi /etc/my.cnf

[mysqld]

port = 3306

character-set-server=utf8mb4
collation-server=utf8mb4_general_ci

# 表名不区分大小写(启动前配置)
lower_case_table_names=1

#设置日志时区和系统一致
log_timestamps=SYSTEM

[client]
default-character-set=utf8mb4

  • 启动服务
#启动服务
systemctl start mysqld

#查看版本信息
mysql -V

#查看状态
systemctl status mysqld

##开机启动
systemctl enable mysqld
systemctl daemon-reload

  • 修改账号账号密码
#1、查看MySQL为Root账号生成的临时密码
grep "A temporary password" /var/log/mysqld.log

#2、进入MySQL shell
mysql -u root -p

#3、修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

# 开启mysql 远程链接

#选择 mysql 数据库:
USE mysql;

#在 mysql 数据库的 user 表中查看当前 root 用户的相关信息:
SELECT host, user, authentication_string, plugin FROM user;

#设置root 用户远程访问:
update user set host = '%' where user ='root';

#刷新权限:
FLUSH PRIVILEGES;

#授权的所有权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

#更新 root 用户密码及加密规则(如果客户端不支持加密插件):
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'MyNewPass4!';

#刷新权限:
FLUSH PRIVILEGES;

# 新建远程用户

#1、新建远程用户
CREATE USER 'devops'@'%' IDENTIFIED BY 'MyNewPass3!';

#2、赋予指定账户指定(数据库名称.表名)远程访问权限
GRANT ALL PRIVILEGES ON mydb_name.* TO 'devops'@'%';

#3、查看权限
SHOW GRANTS FOR 'devops'@'%';

#4、收回权限
REVOKE ALL PRIVILEGES ON *.* FROM 'devops'@'%';

#5、删除用户
DROP USER 'devops'@'%';

#6、刷新权限
FLUSH PRIVILEGES;

# 找回密码

  • 如果忘记了MySQL root密码,可以用以下方法重新设置:
#1.关闭MySQL
service mysql stop

#2.用以下命令启动MySQL,以不检查权限的方式启动;
service mysql start --skip-grant-tables

#3.然后用空密码方式使用root用户登录 MySQL;
mysql -u root

# 修改DataDir 启动报权限error

Setting the MySQL Data Directory Context
The default data directory location is /var/lib/mysql/; and the SELinux context used is mysqld_db_t.

If you edit the configuration file to use a different location for the data directory, or for any of the files normally in the data directory (such as the binary logs), you may need to set the context for the new location. For example:

semanage fcontext -a -t mysqld_db_t "/path/to/my/custom/datadir(/.*)?"
restorecon -Rv /path/to/my/custom/datadir

semanage fcontext -a -t mysqld_db_t "/path/to/my/custom/logdir(/.*)?"
restorecon -Rv /path/to/my/custom/logdir
Setting the MySQL Error Log File Context
The default location for RedHat RPMs is /var/log/mysqld.log; and the SELinux context type used is mysqld_log_t.

If you edit the configuration file to use a different location, you may need to set the context for the new location. For example:

semanage fcontext -a -t mysqld_log_t "/path/to/my/custom/error.log"
restorecon -Rv /path/to/my/custom/error.log

# mysql pasword

  • initial password /var/log/mysqld.log
  • modify passwod

alter user 'root'@'localhost' identified by 'OrcWelcome_123';