CentOS7.6安装mysql8.0、mysql5.7

1、一般CentOS默认安装了mariadb,所以先查看是否安装mariadb,如果安装就需要先卸载mariadb
rpm -qa|grep mariadb
rpm -e mariadb-libs --nodeps

在这里插入图片描述

2、在/usr/local/目录下创建mysql文件夹
cd /usr/local
mkdir mysql

在这里插入图片描述

3、进入mysql文件夹内,下载mysql,地址可能改变,可以去官网复制地址
cd mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar

在这里插入图片描述

4、解压mysql到当前目录
tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar

在这里插入图片描述

5、安装mysql,依次执行下列命令
rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-devel-8.0.16-2.el7.x86_64.rpm --nodeps --force

在这里插入图片描述

6、设置小写不敏感(重要)
vim /etc/my.cnf
追加
lower_case_table_names=1
7、初始化和相关配置,依次执行下列命令
mysqld --initialize; 
chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;
systemctl enable mysqld;

如果执行mysqld --initialize; 出现以下报错,先执行yum -y install numactl,再执行mysqld --initialize;
在这里插入图片描述
如果执行systemctl start mysqld.service; 出现以下报错,先执行tail -f /var/log/mysqld.log查看错误日志
在这里插入图片描述
如果错误日志如下,执行cd /var/lib/mysql,执行rm -rf *删除所有文件,再执行systemctl start mysqld.service;
在这里插入图片描述

8、查看数据库初始化密码
cat /var/log/mysqld.log | grep password

在这里插入图片描述

9、登录数据库,复制粘贴始化密码就行,登录密码不会显示,按回车键
mysql -uroot -p

在这里插入图片描述

10、修改密码,密码需要数字,大小写字母,特殊符号
 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxx';

在这里插入图片描述

11、退出mysql,然后通过新密码再次登陆验证密码是否修改成功
exit; 
mysql -uroot -p

在这里插入图片描述

12、创建远程访问用户,依次执行下列命令
create user 'root'@'%' identified with mysql_native_password by 'xxxxx';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;

在这里插入图片描述

13、一般服务器没有默认开发3306端口,需要在服务器控制台,配置安全组~
14、不建议升到mysql8.0,哈哈哈~~,下载参考Centos7 完全卸载mysql
15、Centos7 安装和配置MySQL5.7
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
yum -y install mysql-community-server

systemctl start  mysqld.service
systemctl status mysqld.service

systemctl enable mysqld
systemctl daemon-reload

grep "password" /var/log/mysqld.log
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

1、修改密码策略

show variables like '%password%';
vi /etc/my.cnf
#添加validate_password_policy配置
validate_password_policy=0
#关闭密码策略
validate_password = off
systemctl restart mysqld

2、远程访问192.168.0.1可访问 如果写%都可以访问

grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
flush privileges; 
exit;
grant all on *.* to root@'%' identified by 'password' with grant option; 
flush privileges;

3、修改编码

show variables like '%character%';
vim /etc/my.cnf
[mysqld]
lower_case_table_names=1
character_set_server=utf8
init_connect='SET NAMES utf8'
systemctl restart mysqld
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值