Centos安装mysql8.0


# centos9的源仓库安装
yum install https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm -y

# centos7的源仓库安装
yum install https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm -y


# 上面安装完成,我们就可以在yum仓库中找到mysql了
# 在仓库中查询 mysql
yum search mysql-community

# 开始安装 mysql-community-server
yum install -y mysql-community-server
# ...
# Installed:
#   mysql-community-client-8.0.31-1.el9.x86_64 mysql-community-client-plugins-8.0.31-1.el9.x86_64 mysql-community-common-8.0.31-1.el9.x86_64
#   mysql-community-icu-data-files-8.0.31-1.el9.x86_64  mysql-community-libs-8.0.31-1.el9.x86_64  mysql-community-server-8.0.31-1.el9.x86_64             
# Complete!

###############################################################################################
MySQL8.0修改表名不区分大小写 (可选)
# 需要在安装MySQL-Server后 启动Server前实现,步骤为:
修改/etc/my.cnf中的变量,添加 lower-case-table-names=1

cat >>/etc/my.cnf<<EOF
#设置mysql不区分大小写
lower-case-table-names=1
EOF

然后执行初始化命令:
mysqld --initialize --user=mysql --lower-case-table-names=1

如果 /var/log/mysql/mysqld.log中有提示以下错误:
# ...[ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
# ...[ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
# ...[ERROR] [MY-010119] [Server] Aborting
rm -rf /var/lib/mysql
###############################################################################################

启动mysql
# 
systemctl start mysqld

获取临时密码
# 
grep "localhost" /var/log/mysqld.log
# ... [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yky;yt=AD9Fj

#mysql8对密码有要求,长度最小8位,包含字母大小写、数字、特殊字符
#先用下面命令修改成符合要求的密码
alter user 'root'@'localhost' identified with mysql_native_password by 'Eleven11.';
#修改完成后,输入quit按回车键退出,再用新密码进行登。

###############################################################################################
登录成功后,修改密码检验标准(可选)
# 
set global validate_password.policy=0;
set global validate_password.length=6;
#开始设置任意6个字符的新密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
#设置成功后退出,再用新密码登录
###############################################################################################

让root用户可以在任意主机上登录(远程navicat)
#切换数据库,查看root登录权限
use mysql;
select host,user from user;

update user set host = '%' where user = 'root';
 
#让刚才修改的配置立即生效
flush privileges;

# 解决mysql8 日志文件中没有错误登入日志的信息
show global variables like "%log_error%";
set global log_error_verbosity = 3;

mysql5.7的安装部署

# 下载5.7.x的源
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

# 安装完成后 mysql57-community-release-el7-9.noarch.rpm 可删除
# 安装mysql
yum install mysql-server -y

# 启动mysql
systemctl start mysqld

# 获取mysql临时密码
grep "localhost" /var/log/mysqld.log

# 使用临时密码登录mysql
mysql -uroot -p$(grep "localhost" /var/log/mysqld.log|awk '{print $NF}')

# 修改登录密码(root)
# 其中 'root'@'localhost'  localhost 为用户对应的host字段
mysql> select user,host from mysql.user ;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | localhost |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

# 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Eleven11.';

# 配置登录
use mysql;
update user set Host='%' where User='root';  
# 说明: % 代表任意的客户端,可替换成具体IP地址。

# 最后刷新权限
flush privileges;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值