CentOS7.X yum安装MySQL8.0 数据表不区分大小写切换默认存储路径
查看当前系统版本的详细信息
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
yum源下载
地址:https://dev.mysql.com/downloads/repo/yum/
下载地址:https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
下载完成后使用yum命令本地安装yum源
# yum localinstall mysql80-community-release-el7-3.noarch.rpm
# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 95
mysql-tools-community/x86_64 MySQL Tools Community 84
mysql80-community/x86_64 MySQL 8.0 Community Server 82
安装MySQL,不启动MySQL
# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# yum install -y mysql-community-server
或者执行这个安装命令:yum install -y mysql-community-server --nogpgcheck
修改默认数据存储路径
默认存储路径是/var/lib/mysql,修改成/data/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
vim /ect/my.cnf
# 原有内容注释掉
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
[mysqld]
bind-address=127.0.0.1
port=3306
datadir=/data/mysql
socket=/data/mysql/mysql.sock
lower_case_table_names=1
default_authentication_plugin=mysql_native_password
default-storage-engine=INNODB
character-set-server=utf8mb4
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
max_user_connections=500
max_connect_errors=10
wait_timeout=1800
interactive_timeout=1800
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
systemctl start mysqld.service
创建软连接文件,方便使用localhost地址登录:ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock
mysql -hlocalhost -P3306 -uroot -p
否则会报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
MySQL常用命令
systemctl start mysqld.service
systemctl status mysqld.service
查看root默认密码
# grep 'temporary password' /var/log/messages
修改root密码
mysql -hlocalhost -P3306 -uroot -p
alter user 'root'@'localhost'IDENTIFIED BY 'eSem?a?ap123';
flush privileges;
创建远程访问的root用户
create user 'root'@'%' identified BY 'eSem?a?ap123';
grant all on *.* to 'root'@'%';
flush privileges;
create user 'root'@'127.0.0.1' identified BY 'eSem?a?ap123';
grant all on *.* to 'root'@'127.0.0.1';
flush privileges;
use mysql;
SELECT `Host`,`User` FROM user;
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;