1、首先安装mysql程序

        命令:sudo apt install mysql-server

        

2、安装完查看mysql启动状态:

        命令:systemctl status mysql

        

3、 直接使用root账户登录然后修改密码就可以了, 代替下面第3步的操作:

       a、 sudo mysql -uroot    回车直接登录

        b、修改密码:alter user 'root'@'localhost' identified with mysql_native_password by '这里是密码';

        c、执行:flush privileges;使密码生效,然后使用root用户登录。

然后第五步开始

3、配置mysql中root密码:

        sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: 
 

这里输入:Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 

这里是密码强度:我服务器搭建的所以我选择:0

Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 

这里是创建密码,

其余的下面全部是Y就可以了 

4、登录root用户:

        如果登入用户错:Enter password: 
                ERROR 1698 (28000): Access denied for user 'root'@'localhost'

        需要重置root用户密码:

               先查看获取默认用户: sudo vim /etc/mysql/debian.cnf

                找到:        用户名:user     = debian-sys-maint
                                密码:password = ecMdhCUfmsLmyGOq

                用默认用户登录:

                

                 修改密码:alter user root@localhost identified with mysql_native_password by '这里是密码';

                修改成功字样:Query OK, 0 rows affected (0.01 sec)

               执行:flush privileges;使密码生效,然后使用root用户登录。

5、创建自己的用户:

        create user '用户名'@'%' identified with mysql_native_password by '密码';

6、授权用户远程登录:

        grant all privileges on *.* to '用户'@'%' with grant option;

7、刷新策略:flush privileges;

完成了,直接远程登录。

如果远程登录不上错误10038需要修改一个文件,

修改一个配置文件:sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

        注释掉:#bind-address    = 127.0.0.1

然后重启mysql服务,即可远程登录了
 

--------------------------------------------------------------------------------------------------------------------------------

 修改密码强度

1、查看需要修改的规则: show variables like 'validate_password';

                

2、修改需要设置密码的验证强度等级: set global validate_password.policy=LOW;

 3、其他的以此类推:

        1)、validate_password.length  固定密码的总长度;
        2)、validate_password.dictionary_file 指定密码验证的文件路径;
        3)、validate_password.mixed_case_count  整个密码中至少要包含大/小写字母的总个数;
        4)、validate_password.number_count  整个密码中至少要包含阿拉伯数字的个数;
        5)、validate_password.policy 指定密码的强度验证等级,默认为 MEDIUM;

4、再次修改密码即可

                

 卸载mysql方法

  1. 关闭MySQL服务:systemctl stop mysql
  2. 卸载相关依赖文件:sudo apt remove --purge mysql-*
  3. 自动清理残余:sudo apt autoremove
  4. 查看是否清理赶紧:sudo dpkg --list | grep mysql

更多推荐