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
mysql -u<username> -p
mysql -uroot -p mysql> create database some_database; mysql> use some_database; mysql> source some_database.sql;
The third line runs the named sql file for the database you names.
Create a new user
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';
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
mysql -uroot -p mysql> SET PASSWORD FOR 'username'@'localhost' = PASSWORD('new_password');
Restart mysql:
sudo /etc/init.d/mysql restart
Pingback: Checklist: Moving Wordpress site to a New Host | Coding and Server Syntax Examples
Pingback: Installing MySQL on Snow Leopard | Coding and Server Syntax Examples
Pingback: Reset Root Password on MySQL Database | Coding and Server Syntax Examples
Pingback: How to Dump SQL Result to a Text File | Coding and Server Syntax Examples
Pingback: Some Quick cli Syntax for Postgres | Coding and Server Syntax Examples