【转】How to create a new user and grant permissions in MySQL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【转】How to create a new user and grant permissions in MySQL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2651字,纯文字阅读大概需要4分钟。
内容图文
![【转】How to create a new user and grant permissions in MySQL](/upload/InfoBanner/zyjiaocheng/918/fc92a3380a1f4da9840c5e0f37557ae9.jpg)
MySQL is one of the most popular database management systems. In this tutorial we will cover the steps needed to create new MySQL user and grant permissions to it in CentOS 6.4, Debian or Ubuntu platform.
Requirements
- CentOS 6.4, Debian or Ubuntu installed on your computer/server
- SSH access (Command line access to the server)
- root privileges
- Basic skills for working on a Linux environment
- LAMP installed on the server
All operation will be executed inside a MySQL prompt with the root user:
mysql -p -u root
You will be prompted to fill in the MySQL root password.
Create a new user
We can create new MySQL user with the following command:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
where:
- user – the name of the MySQL user which will be created
- password – the password which we want to assign to that user
All MySQL commands are engin with a semicolon (;).
Grant permissions for a user
The next thing that we will have to do is to grant privileges for that user in order to be able to access the MySQL client and to work with the corresponding database/s:
GRANT ALL PRIVILEGES ON database.table TO 'user'@'localhost';
where:
- database – the name of the MySQL database to which we grant access
- table – the name of the database table to which we grant access
We are allowed to use the asterisk wildcard symbol (*) when we want to grant access to all databases/tables:
GRANT ALL PRIVILEGES ON database.* TO 'user'@'localhost';
or
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost';
With the first command we grant all privileges to the MySQL user to all database tables related to the database with name "database".
In the second case access for the user is granted to all databases.
Here is a list of the MySQL privileges which are most commonly used:
- ALL PRIVILEGES – grants all privileges to the MySQL user
- CREATE – allows the user to create databases and tables
- DROP - allows the user to drop databases and tables
- DELETE - allows the user to delete rows from specific MySQL table
- INSERT - allows the user to insert rows into specific MySQL table
- SELECT – allows the user to read the database
- UPDATE - allows the user to update table rows
Here is a sample syntax where only two privileges are granted for the user:
GRANT SELECT, INSERT, DELETE ON database.* TO 'user'@'localhost';
In order for the changes to take effect and the privileges to be saved the following command should be executed at the end:
FLUSH PRIVILEGES;
Remove an existing MySQL user
A MySQL user can be deleted with the following command:
DROP USER 'user'@'localhost'
Reference:
https://kyup.com/tutorials/create-new-user-grant-permissions-mysql/ How to create a new user and grant permissions in MySQL
内容总结
以上是互联网集市为您收集整理的【转】How to create a new user and grant permissions in MySQL全部内容,希望文章能够帮你解决【转】How to create a new user and grant permissions in MySQL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。