mysql用户修改登录密码及开启远程登录
2015-04-20 14:30
190 查看
一、修改用户登录密码:
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> quit
Bye
[root@rhel204 ~]# mysqladmin -uroot -p password --修改用户密码
Enter password:
New password:
Confirm new password:
[root@rhel204 ~]# mysql -uroot -p --以新密码登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)
二、开启用户远程登录权限
--加-h参数远程登录mysql数据库提示如下错误
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204
Enter password: *****
ERROR 1130 (HY000): Host '192.168.1.123' is not allowed to connect to this MySQL server
错误分析:主机'192.168.1.123'不允许连接到mysql数据库(没权限)。
[root@rhel204 ~]# myslq -uroot -p --本地登录
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> select user,password,host from user; --查看用户信息,的确root账号只允许本地登录。
+------+-------------------------------------------+-------------+
| user | password | host |
+------+-------------------------------------------+-------------+
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | localhost |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | rhel204.com |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | 127.0.0.1 |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | ::1 |
+------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)
mysql> grant all privileges on *.* to root@'%' identified by 'rusky'; --授权
Query OK, 0 rows affected (0.03 sec)
或:grant all on db1.* to username1@'%'; --授权用户username1从任一客户端远程登录数据库db1,并允许对库db1做所有操作。
"%"表示任何主机都可以远程登录到该服务器上访问。
*.*表示所有库的所有对象。
如果要限制只有某台机器可以访问,将%换成相应的IP即可,如:
GRANT ALL PRIVILEGES ON *.* TO username2@‘192.168.1.123’; --可省略IDENTIFIED BY '密码';或with grant option;
mysql> flush privileges; --刷新权限
Query OK, 0 rows affected (0.04 sec)
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204 --root账号远程登录
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql>
三、创建用户时就限制用户的权限:
create user 'lxj'@'%' identified by '123123';
@后面参数指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> quit
Bye
[root@rhel204 ~]# mysqladmin -uroot -p password --修改用户密码
Enter password:
New password:
Confirm new password:
[root@rhel204 ~]# mysql -uroot -p --以新密码登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)
二、开启用户远程登录权限
--加-h参数远程登录mysql数据库提示如下错误
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204
Enter password: *****
ERROR 1130 (HY000): Host '192.168.1.123' is not allowed to connect to this MySQL server
错误分析:主机'192.168.1.123'不允许连接到mysql数据库(没权限)。
[root@rhel204 ~]# myslq -uroot -p --本地登录
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> select user,password,host from user; --查看用户信息,的确root账号只允许本地登录。
+------+-------------------------------------------+-------------+
| user | password | host |
+------+-------------------------------------------+-------------+
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | localhost |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | rhel204.com |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | 127.0.0.1 |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | ::1 |
+------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)
mysql> grant all privileges on *.* to root@'%' identified by 'rusky'; --授权
Query OK, 0 rows affected (0.03 sec)
或:grant all on db1.* to username1@'%'; --授权用户username1从任一客户端远程登录数据库db1,并允许对库db1做所有操作。
"%"表示任何主机都可以远程登录到该服务器上访问。
*.*表示所有库的所有对象。
如果要限制只有某台机器可以访问,将%换成相应的IP即可,如:
GRANT ALL PRIVILEGES ON *.* TO username2@‘192.168.1.123’; --可省略IDENTIFIED BY '密码';或with grant option;
mysql> flush privileges; --刷新权限
Query OK, 0 rows affected (0.04 sec)
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204 --root账号远程登录
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql>
三、创建用户时就限制用户的权限:
create user 'lxj'@'%' identified by '123123';
@后面参数指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.
相关文章推荐
- CentOS6.5下通过Shell修改MySQL初始密码,开启远程登录,授权远程登录用户
- Linux下修改MySQL初始密码、开启远程登录、授权远程登录用户
- CentOS6.5下通过Shell修改MySQL初始密码,开启远程登录,授权远程登录用户
- mysql 小记 增删改 从文件读取到表中 修改远程登录用户 更改ocs用户密码
- CentOS修改mysql 用户root的密码并允许远程登录
- linux系统下修改mysql 数据库的root用户密码和开启远程用户
- mysql修改登录密码、创建新的登录用户、开启外部访问的端口
- mysql 5个常用操作,添加用户配置对应数据库,开启远程访问,修改密码
- CentOS修改mysql 用户root的密码并允许远程登录
- CentOS 初始化时普通用户修改ROOT密码并且开启远程登录
- CentOS修改mysql 用户root的密码并允许远程登录
- mysql远程登录及修改用户密码
- linux使用mysql(卸载,安装,修改密码,远程登录)
- mysql给root开启远程访问权限,修改root密码
- Mysql修改密码,远程登录,ERROR 1044 (42000)错误解决办法
- Centos 7 mysql 5.7 给root开启远程访问权限,修改root密码
- mysql给root开启远程访问权限,修改root密码
- MYSQL 下一些常用操作命令:新建用户、修改密码、修改登录host等
- mysql开启root用户可远程登录方法
- Mysql密码找回及开启root远程登录