【Linux】yum源安装mysql(待整理)
MySQL :: Download MySQL Yum Repository
添加 MySQL Yum 存储库
注意:这里可能会出现如下错误 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
GPG key retrieval failed: [Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022”
(若正常跳过即可)
执行 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
即可
mysql8 设置简单密码
-
获取初始密码
- grep 'temporary password' /var/log/mysqld.log
-
显示密码策略
- show variables like '%password%';
-
修改校验密码策略等级(MEDIUM -> LOW)
- set global validate_password.policy=LOW;
-
设置密码长度
- set global validate_password.length=6;
-
大小写敏感
- show variables like '%lower%';
- lower_case_table_names=0 此时没有开启
- 修改/etc/my.cnf 添加 lower_case_table_names=1
- systemctl stop mysqld
- 如果mysql已经安装好了,则需要删除mysql的数据库数据才能重新启动成功
- 备份并删除/etc/my.cnf里指向的datadir文件
- 启动服务systemctl start mysqld
-
修改密码
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'root@supconit2022';
- 如果提示ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost',则查看user表中host是否为其他类型,其中%表示任意地址都可以通过此账户访问数据库
- use mysql;
- select host,user,max_questions,max_connections,max_user_connections,plugin,authentication_string,password_expired,password_last_changed,password_lifetime,account_locked from user;
- 看到root用户的host是%
- ALTER USER 'root'@'%' IDENTIFIED BY 'root@supconit2022';
-
远程连接出错时
-
第一种:账户开放允许连接的host
- use mysql;
- select host,user from user where user='root';
- update user set host = '%' where user ='root';
- flush privileges;
- select host,user from user where user='root';
-
第二种:连接工具版本太低,mysql8的加密方式caching_sha2_password不支持
- 可以调整密码策略,兼容旧版本加密方式
- 查看账号加密方式,然后修改密码和加密方式
- select host, user, authentication_string, plugin from user;
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root@supconit2022';
-
-
navicat提示too many connection
-
/etc/my.cnf 添加如下配置 (hikariCP连接池默认maxlifetime=30min)
-
wait_timeout = 1800
interactive_timeout = 1800
-
重启mysqld服务
-
可以在mysql内部使用
show processlist;
命令查看当前连接数量,如果达到了max_conncetions
默认连接数量时,可以通过命令实时修改参数值set persist max_connections = 300;
增大连接数量,此命令会把配置持久化到mysql_auto.conf中
-
-
卸载mysql
-
rpm -qa|grep mysql
-
yum remove mysql mysql-server mysql-libs mysql-server
-
rpm -qa|grep mysql
-
rpm -ev mysql-community-common-8.0.30-1.el7.x86_64 mysql-community-client-plugins-8.0.30-1.el7.x86_64 mysql-community-icu-data-files-8.0.30-1.el7.x86_64
-
删除 /var/lib/mysql(权限:0751,这里是MySQL数据库文件,有需要可以备份)
-
删除 /var/log/mysqld.log mysql操作日志
-
正 在 安 装 :
mysql-community-server x86_64 8.0.30-1.el7 mysql80-community 54 M
为 依 赖 而 安 装 :
mysql-community-client x86_64 8.0.30-1.el7 mysql80-community 14 M
mysql-community-client-plugins x86_64 8.0.30-1.el7 mysql80-community 2.5 M
mysql-community-common x86_64 8.0.30-1.el7 mysql80-community 645 k
mysql-community-icu-data-files x86_64 8.0.30-1.el7 mysql80-community 2.1 M
mysql-community-libs x86_64 8.0.30-1.el7 mysql80-community 1.5 M
已 安 装 :
mysql-community-server.x86_64 0:8.0.30-1.el7
作 为 依 赖 被 安 装 :
mysql-community-client.x86_64 0:8.0.30-1.el7 mysql-community-client-plugins.x86_64 0:8.0.30-1.el7
mysql-community-common.x86_64 0:8.0.30-1.el7 mysql-community-icu-data-files.x86_64 0:8.0.30-1.el7
mysql-community-libs.x86_64 0:8.0.30-1.el7