자주사용하는 Mariadb 명령어

자주사용하는 Mariadb 명령어

Access MySQL

$ mysql -u root -p

Show All database

mysql> SHOW DATABASES;

Create new database

mysql> CREATE DATABASE DATABASE_NAME;
mysql> FLUSH PRIVILEGES;

Delete new database

mysql> DROP DATABASE DATABASE_NAME;
mysql> FLUSH PRIVILEGES;

Show All User

mysql> USE mysql;
mysql> SELECT user, host FROM user;

Create new user

mysql> CREATE USER 'ubuntu'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
mysql> GRANT ALL ON DATABASE_NAME.* TO 'ubuntu'@'localhost';
mysql> FLUSH PRIVILEGES;

Delete user

mysql> DROP USER 'ubuntu'@'localhost';
mysql> FLUSH PRIVILEGES;

Password generate using javascript

window.btoa('ubuntu') // dWJ1bnR1

Password change

mysql> ALTER USER 'ubuntu'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
mysql> FLUSH PRIVILEGES;

Clone Database

$ mysql -uroot -PASSWORD -e 'CREATE DATABASE NEW_DATABASE_NAME;'
$ mysqldump -uroot -PASSWORD OLD_DATABASE_NAME | mysql -uroot -PASSWORD NEW_DATABASE_NAME
$ mysql -uroot -PASSWORD -e 'DROP DATABASE OLD_DATABASE_NAME;'
$ mysql -uroot -PASSWORD -e "CREATE USER 'NEW_USER_NAME'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';"
$ mysql -uroot -PASSWORD -e "GRANT ALL ON NEW_DATABASE_NAME.* TO 'NEW_USER_NAME'@'localhost';"
$ mysql -uroot -PASSWORD -e "FLUSH PRIVILEGES;"
Scroll to Top