Mysql Commands

Login to Mysql

mysql -u root -p

Mysql restore Dump

mysql -u root -p < path_to_file

use db_name;
source /var/www/html/db.sql


mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

== export dump ==

mysqldump -u username -p dbname > dbname.sql

== export table dump ==

mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql

== reset mysql password ====

mysql -u root -p
use mysql;
update user set password=PASSWORD('your_new_password') where User='root';
flush privileges;
quit

== dump with where condition ====

mysqldump -t -u root -p  mytestdb mytable --where="datetime LIKE '2014-09%'"

== create database with utf8===

CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci;

== Mysql socket path =====

/var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock

== restart mysql server ==

/etc/init.d/mysql start 

Leave a Reply

Your email address will not be published. Required fields are marked *