MySQL常用命令整理
一、给root开启远程访问权限,修改root密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
mysql> USE mysql; -- 切换到 mysql DB Database changed mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机 +------+----------+-----------+ | User | Password | Host | +------+----------+-----------+ | root | | localhost | +------+----------+-----------+ row in set (0.00 sec) mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接 mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION; mysql> -- @'192.168.1.100'可以替换为@‘%’就可任意ip访问,当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下: mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1; mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) |
二、修改root密码
1 2 3 4 5 6 7 8 9 10 11 12 13 |
mysql> USE mysql; -- 切换到 mysql DB Database changed mysql> update user set password=PASSWORD('123456') where user='root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) |
待续…