nortmas
11/7/2016 - 10:45 AM

MySQL

/etc/init.d/mysql stop
#or
ps aux | grep mysql
sudo kill -9 <num_process>

# automatic script
ps aux | grep mysqld | grep -v grep | awk '{print $2}' | sudo xargs kill -9 && sudo service mysql restart
#or
ps aux | grep mysql | grep -v grep | awk '{system "kill -9" $2}'
# сделать дамп
mysqldump -u root -p db_name > file_name.sql
# развернуть дамп
mysql -u root -p db_name < file_name.sql
# развернуть дамп
backup/dump.mysql | mysql -u root -p -h localhost db_name
# сразвернуть дамп используя pv
pv file_name.sql | mysql -u root -p db_name
# see tutorial: https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 

mysql -u root -p                   # login db

SHOW DATABASES;                    # show databases
CREATE DATABASE database_name;     # create database
DROP DATABASE database_name;       # clean database 

USE events;                        # open data base we want to use.
SHOW tables;                       # show tables of chocen db


# change password for root
sudo /etc/init.d/mysql stop
sudo mysqld --skip-grant-tables &
mysql -u root mysql
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit; 


# Copy/duplicate database without using mysqldump
mysqldump -h [server] -u [user] -p[password] db1 | mysql -h [server] -u [user] -p[password] db2
# example: 
mysqldump -u root -p db1| mysql -u root -p db2; # and two times enter password (one after another)