1.卸载系统自带的MySQL组件,删除一切和MySQL相关的东西。
rm -rf /var/lib/mysql
1.可以在自己喜欢的文件夹下下载
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 install mysql-community-server
yum install mysql-community-client
1.安装好之后,先查看MySQL启动状态
systemctl status mysqld
systemctl start mysqld
systemctl enable mysqld
systemctl daemon-reload
1.先从mysqld.log中查看密码
grep 'temporary password' /var/log/mysqld.log
2.红色圈出的即默认的root密码,可以把它复制过来登录试试
mysql -uroot -p
3.然后粘贴刚才复制的密码,就可以登录MySQL了
4.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你想设置的密码';
5.此时会发现,修改失败了,密码设置不符合策略,一般是因为我们设置的密码过于简单等等。下面我们去设置密码策略,把策略禁用,就可以随意设置自己想要的密码了
vi /etc/my.cnf
6.添加以下内容:validate_password=off
7.然后重启mysql服务,使配置生效
systemctl restart mysqld
8.下面接着修改密码(先用默认密码登录后再执行)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
1.查看数据库
show databases;
GRANT ALL PRIVILEGES ON *.* TO 'hunter'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
create database mydb;
show databases;
use mydb
create table mytable(id int,name varchar(100));
insert into mytable values(1,"张三");
1.在第五节,发现存入中文字符时报错,这是字符集的问题,下面给出解决办法
先查看字符集
show variables like 'character%';或#~ show variables like '%char%';
show variables like '%char%';
set character set database=utf8;
show variables like '%char%';
set character_set_server=utf8;
3.下面再进行中文字符的录入,就没有问题了,给出几张操作截图
注: 参考视频链接:
https://www.bilibili.com/video/BV1Vp4y1Q7KZ?from=search&seid=7312941883866161621
systemctl daemon-reexec
参考链接:https://blog.csdn.net/weixin_38319647/article/details/81001696
卸载MySQL相关组件参考链接:
https://blog.csdn.net/sms15732621690/article/details/80900524
当之前安装过,重新安装后MySQL启动不成功,大多因为权限问题,具体解决办法,后续不断更新。