tips:
快速的让某个账户能远程访问并且访问所有数据库(例如用户名root,密码root)
select host,user,password from mysql.user;
grant usage on *.* to root identified by 'root'
grant all privileges on *.* to root@'%' identified by 'root' with grant option;
select host,user,password from mysql.user;
让部署的程序可以通过localhost 来访问
grant all privileges on *.* to root@'localhost' identified by 'root' with grant option;
安装mysql客户端
yum install mysql
安装mysql服务端
yum install mysql-server
yum install mysql-devel
查看状态
service mysqld status
启动
service mysqld start
查看用户名
直接运行mysql进去
mysql> select host,user,password from mysql.user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| dn3 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| dn3 | | |
+-----------+------+----------+
创建密码
mysqladmin -u root password 1234
创建一个对所有数据库都有权限的账户
mysql>grant all privileges on *.* to bao@'%' identified by 'bao' with grant option
之后查看
mysql> select host,user,password from mysql.user;
+-----------+-------------+-------------------------------------------+
| host | user | password |
+-----------+-------------+-------------------------------------------+
| localhost | root | *A4B6157319038724E3560894F7F932C8886EBFCF |
| dn3 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| dn3 | | |
| % | bao | *564ACA7DA0378381D68D3E98ACFF92EE56C7791F |
让远程可以用root账户链接数据库
mysql> grant usage on *.* to root identified by '1234';
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from mysql.user;
+-----------+--------+-------------------------------------------+
| host | user | password |
+-----------+--------+-------------------------------------------+
| localhost | root | *A4B6157319038724E3560894F7F932C8886EBFCF |
| dn3 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| dn3 | | |
| % | bao | *564ACA7DA0378381D68D3E98ACFF92EE56C7791F |
| % | root | *A4B6157319038724E3560894F7F932C8886EBFCF |
+-----------+--------+-------------------------------------------+
创建一个可以任意IP访问的用户,但是没有创建表的权限
CREATE USER 'dragon_stat'@'%' IDENTIFIED BY 'dragon_stat';
其他
查看当前用户
mysql> select user();
测试:
CREATE USER 'dragon_stat2'@'%' IDENTIFIED BY 'dragon_stat2'; 可以远程登陆,但不可以远程建库
再次执行grant all privileges on *.* to dragon_stat2@'%' identified by 'dragon_stat2' with grant option 则可以建表并查看其他数据库
总之,只执行grant all privileges on *.* to dragon_stat2@'%' identified by 'dragon_stat2' with grant option 就可以远程登陆,并且穿件数据库
tips:为某用户添加localhost的链接权限
GRANT ALL PRIVILEGES ON *.* TO gao@'localhost' IDENTIFIED BY 'gao' WITH GRANT OPTION
2022年04月04日 修改密码
select host,user,password from mysql.user;
mysqladmin -uroot -proot password test$$$
修改其他的密码
update user set password = PASSWORD('test!!!@#') where user ='root'
flush privileges;