This article explains how to use the mysql program to perform common MySQL database administration tasks from the command line. Among these common tasks are the creation and deletion of databases, users, and tables.
User and database creation
Follow these steps to create a MySQL database and user:
- Log in to MySQL as the root user at the command line:
mysql -u root -p
- Enter the MySQL root password after typing it.
- Enter the following command to create a database user. Replace username with the username you want to create, and password with the password for the user:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';
The preceding command grants the user full access to all databases. You can, however, grant specific permissions to maintain complete control over database access. To explicitly grant only the SELECT permission to a specific user, for example, use the following command:
GRANT SELECT ON *.* TO 'username'@'localhost';
You would use the following command to grant the user all permissions only on the database named dbname:
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
More information on MySQL database permissions can be found at https://dev.mysql.com/doc/refman/5.5/en/grant.html.
Cras odio felis, pulvinar vel massa at, semper tempor ipsum. Donec eget diam eget urna convallis dictum sed eu est. Proin vehicula dapibus nulla nec tincidunt. Nullam eget ultricies felis, at mattis turpis. Vestibulum varius egestas aliquam. Sed interdum nisl vel nunc cursus, nec maximus leo efficitur. Donec viverra id ante at euismod. In hac habitasse platea dictumst. Mauris et ipsum nec nibh feugiat lacinia. Nullam ex nulla, cursus a ante non, mattis interdum orci. Phasellus sodales risus id tincidunt viverra. Duis vulputate, nunc et luctus vehicula, libero ligula venenatis ligula, non luctus risus sapien nec nulla. Sed sollicitudin viverra diam, at faucibus erat euismod et.
Duis quis ligula sollicitudin, fermentum elit pellentesque, porttitor metus. Proin accumsan sed ligula sit amet suscipit. Nunc euismod, orci id imperdiet iaculis, nulla orci varius lorem, quis cursus tortor metus id lorem. Vivamus eget leo sem. Maecenas massa leo, condimentum sit amet luctus a, sagittis vel lacus. Phasellus scelerisque lacus nec massa posuere eleifend. Nullam tempus felis malesuada nulla ultricies, at pellentesque enim accumsan. Duis id cursus diam.
Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.