1. 卸载MySQL
# 停止服务
systemctl stop mysqld
# 查找安装mysql的rpm包
rpm -qa | grep -i mysql
# 卸载
yum remove <rpm 命令列出的内容>
# 查看是否卸载干净
rpm -qa | grep -i mysql
# 查找mysql相关目录
find / -name mysql
# 删除残留文件
rm -rf <find 命令列出的内容>
# 删除配置文件
rm -rf /etc/my.cnf
rm -rf /etc/my.cnf.rpmsave
2. 重新安装mysql
# 在官网下载 rpm 文件
https://dev.mysql.com/downloads/repo/yum/
# 此处以 centos-7 版本为例
wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
# 使用 yum 安装 mysql-8.0.x
yum install mysql80-community-release-el7-7.noarch.rpm
yum repolist enabled | grep mysql.*
yum install mysql-community-server
# 修改 mysql 配置 (注意!必须先修改配置文件再启动 mysql)(配置文件附到文章末尾)
vim /etc/my.cnf
# 修改配置后启动 mysql
systemctl start mysqld
3. 修改 mysql 密码
# 安装后查看初始密码
grep "password" /var/log/mysqld.log
# 进入mysql初次修改密码
mysql -uroot -p
# 初次修改密码(注意:此处密码不能过于简单否则无法修改成功)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab123@456.';
(PS:如果想修改密码为简单密码如:123456,可以参考我的另一篇博客)
# 刷新权限
FLUSH PRIVILEGES;
4. 允许 root 远程访问文章来源:https://www.toymoban.com/news/detail-530370.html
# 链接 mysql
mysql -uroot -p
# 选择 mysql 数据库
use mysql;
# 修改 root host
update user set host='%' where user='root';
# 刷新权限
FLUSH PRIVILEGES;
附录:my.cnf文章来源地址https://www.toymoban.com/news/detail-530370.html
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[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
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 设置为 False, 在客户端字符集和服务端字符集不同的时候将拒绝连接到服务端执行任何操作
character-set-client-handshake=FALSE
# 声明服务端的字符编码
character-set-server=utf8mb4
# 声明服务端的字符集
collation-server=utf8mb4_general_ci
# 声明使用的是 utf8mb4 的字符编码
init_connect='SET NAMES utf8mb4'
# 表名忽略大小写
lower_case_table_names=1
# 永久关闭only_full_group_by模式
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
# 开启bin-log日志
server-id=1
log-bin=/var/lib/mysql/mysql-bin
binlog-format=ROW
# 开启慢查询日志
slow_query_log = 1
# 指定慢查询日志路径
slow_query_log_file = /var/lib/mysql/slow-query.log
# 表示查询时间>=1秒才记录日志
long_query_time = 5
# 表明记录没有使用索引的 SQL 语句
log_queries_not_using_indexes = 1
到了这里,关于Centos7 安装并配置MySQL 8.0.x 忽略表名大小写的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!