版本:
Centos: 7,
CPU: x86_64
MySQL:8.0
写在前面,如果需要MySQL区分大小写,则应该在第一次启动MySQL之前,找到mysqld(/usr/sbin/mysqld),使用如下命令启用一次:
mysqld --initialize --lower-case-table-names=1
然后,在/etc/my.cnf中添加同样的参数:
[mysqld]
lower-case-table-names=1
- 官网下载对应linux发行版本的RPM集成压缩包(bundle,700多M),包含MySQL所有依赖,记得区分处理器x86平台和ARM平台;
- 解压,按顺序安装rpm包,先从依赖包开始安装,如果缺少依赖,会提示你是哪一个,按照提示安装即可
rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm
- 安装好后启动mysql
systemctl start mysqld
查看启动状态:
systemctl status mysqld
- 获取临时密码
grep 'temporary password' /var/log/mysqld.log
问题来了
- 登录**(坑1)**:
mysql -u root -p
输入临时密码无效
- 使用skip-grant-tables跳过密码登录
vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
- 重启mysql,重新登录,修改密码**(坑2)**
alter user 'root'@'localhost' identified by 'root';
提示:使用了skip-grant-tables,不能修改密码**(WTF)**
- 解决办法,先执行以下命令:
flush privileges;
再使用步骤3的命令修改密码,大功告成!
mysql> alter user 'root'@'localhost' identified by 'xxxxxxx';
Query OK, 0 rows affected (0.01 sec)
- 去掉my.ini中的skip-grant-tables参数,重启mysql,就可以愉快地玩耍了!
创建用户,添加权限
CREATE USER 'custom'@'%.example.com' IDENTIFIED BY 'password';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON customer.addresses TO 'custom'@'%.example.com';