MySQL cli Syntax

Some MySQL cli syntax examples

How to create a MySQL database and import tables, data… from a sql file.

Login to the MySQL command line interface

[bash]mysql -u<username> -p[/bash]

[sql]mysql -uroot -p
mysql> create database some_database;
mysql> use some_database;
mysql> source some_database.sql;[/sql]

The third line runs the named sql file for the database you names.

Create a new user

[sql]mysql -uroot -p
mysql> USE ‘some_database’;
mysql> CREATE USER ‘new_user’@’localhost’ IDENTIFIED BY ‘user_password’;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON some_database.* TO ‘new_user’@’localhost’;
[/sql]

For some reason MySQL chooses to say 0 rows affected, when it succeeds and ads a row for the user. Anyway if you get that message, it worked.

Change password for a user

[sql]mysql -uroot -p
mysql> SET PASSWORD FOR ‘username’@’localhost’ = PASSWORD(‘new_password’);[/sql]

Restart mysql: [bash]sudo /etc/init.d/mysql restart[/bash]

5 thoughts on “MySQL cli Syntax

  1. Pingback: Checklist: Moving Wordpress site to a New Host | Coding and Server Syntax Examples

  2. Pingback: Installing MySQL on Snow Leopard | Coding and Server Syntax Examples

  3. Pingback: Reset Root Password on MySQL Database | Coding and Server Syntax Examples

  4. Pingback: How to Dump SQL Result to a Text File | Coding and Server Syntax Examples

  5. Pingback: Some Quick cli Syntax for Postgres | Coding and Server Syntax Examples

Leave a Reply

Your email address will not be published.

This Blog will give regular Commentators DoFollow Status. Implemented from IT Blögg