首页
Mysql 安装初始化

修改root密码

在其配置文件/etc/my.cnf中加入skip-grant-tables=1即可

[mysqld]
skip-grant-tables=1

然后重启mysql,使用mysql命令即可进入

[iaas@yf-centos ~]$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

修改mysql root密码

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set authentication_string = password("123456") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

然后将/etc/my.cnf中的skip-grant-tables=1注释掉,重启mysql服务即可。

在此要注意的是,之前版本密码修改字段为password,在5.7版本之后字段为authentication_string

授权

例如,你想root使用123456从任何主机连接到mysql服务器。

mysql>``GRANT` `ALL` `PRIVILEGES` `ON` `*.* ``TO` `'root'``@``'%'` `IDENTIFIED ``BY` `'123456'` `WITH` `GRANT` `OPTION``;

如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码

`mysql>``GRANT` `ALL` `PRIVILEGES` `ON` `*.* ``TO` `'jack'``@’10.10.50.127’ IDENTIFIED ``BY` `'654321'` `WITH` `GRANT` `OPTION``;``mysql>FLUSH RIVILEGES`