如何在MySQL中创建具有全部权限的用户?

时间:2019-05-19 01:25:50  来源:igfitidea点击:

语法

mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

mysql> GRANT ALL ON [dbname].[table] TO 'username'@'localhost';

实现

首先登录到mysql的root帐户和使用下面的命令在mysql中创建拥有全部权限的新用户Hyman。
但是该用户只能从本地主机访问数据库服务器。

mysql> CREATE USER 'Hyman'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL ON *.* TO 'Hyman'@'localhost' IDENTIFIED BY 'secret_password';
mysql> FLUSH PRIVILEGES;

现在,尝试使用新密码登录

# mysql -u Hyman -p'password'

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9522
Server version: 5.5.30-cll MySQL Community Server (GPL) by Atomicorp

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>