Linux安装mysql8

安装mysql

如果你是ubuntu,把yum换成apt就可以了

# 执行过这个更新操作然后安装mysql,自然就是8的版本了,不然的话就是5.7的版本
yum update -y 

# 直接安装
yum install mysql-server -y

配置mysql,root用户

# 如果用root账号登录linux/ubuntu系统的话,可以不要密码,直接输入mysql -uroot 就可以了
mysql -uroot 

# 如果你是用了其他的账号登录了linux/ubuntu系统的话,那么就要输入密码了
mysql -uroot -p your_pwd

# 进入到mysql之后 
use mysql; 

# 查看当前的用户数据
select user, host from user;
# 你会看到有个默认的root账号,但是登录权限是localhost,
# 如果直接 update user set host='%' where user='root';
# 会出现大问题,网络上好多人在讲 这个命令,但是实际上是很智障的做法
# 这个问题就是(可能是),root账号无法登录到本地了。

# 正确操作是:

# 创建一个新的%的root账号 密码是3369**++
CREATE USER 'root'@'%' IDENTIFIED BY '3369**++';

# 修改密码的强度或者加密方式,这个语句的概念我是模糊的,总之梭哈就完事了、
ALTER USER 'root'@'%' IDENTIFIED with mysql_native_password BY '3369**++';
# 给这个root账号设置最高权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

# 修改密码的强度或者加密方式,这个语句的概念我是模糊的,总之梭哈就完事了、
ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password BY '3369**++';
# 给这个root账号设置最高权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

# 刷新一下权限,直接起飞
flush privileges;

强制修改密码

1、找到my.cnf文件
    [mysqld] 下面写一行
    skip-grant-tables

2、重启mysql服务

3、mysql -uroot -p
   直接回车进入mysql

4、 flush privileges;

5、直接修改密码
    ALTER USER 'root'@'localhost' IDENTIFIED BY '112233445566';
    ALTER USER 'root'@'%' IDENTIFIED BY '112233445566';

6、flush privileges;

常用命令

systemctl status mysql 
systemctl start mysql 
systemctl stop mysql 
systemctl restart mysql 
systemctl enable mysql 
systemctl status mysql 

systemctl stop mysql && systemctl start mysql  &&  systemctl status mysql 
systemctl start mysql

results matching ""

    No results matching ""