Lệnh MYSQL / MARIADB thường dùng

CREATE USER

  • User on localhost/IP other:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
// CREATE USER 'dev'@'localhost' IDENTIFIED BY 'dev@123';
  • User on all IP:
CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
// CREATE USER 'dev'@'%' IDENTIFIED BY 'dev@123';
  • Change user password:
SET PASSWORD FOR 'username'@'%' = PASSWORD('passwd');

GRANT USER

  • Gán vào tất cả IP:
GRANT ALL PRIVILEGES ON `db` . `tbl` TO 'dev'@'%';
// GRANT ALL PRIVILEGES ON * . * TO 'dev'@'%';
  • Gán vào localhost:
GRANT ALL PRIVILEGES ON db. * TO dev@'localhost';
// GRANT ALL PRIVILEGES ON * . * TO dev@'localhost';
  • Gán vào 1 IP:
GRANT ALL PRIVILEGES ON ecommerce . * TO 'admin'@'210.222.000.111';

FLUSH TO APPLY GRANT

FLUSH PRIVILEGES;

COMMAND

Show list user:

SELECT user,host,password FROM mysql.user;

Import database mysql / mysqld:

mysql -u user_root -p --database = db_name < /root/db.sql

Dump database mysql / mysqld:

mysqldump -u user_root -p database_name > /root/database_backup.sql

Copy database

#As the manual says in Copying Databases you can pipe the dump directly into the mysql client:
mysqldump db_name | mysql new_db_name


# Both mysqldump and mysql commands accept options for setting connection details (and much more), like:
mysqldump -u <user name> --password=<pwd> <original db> | mysql -u <user name> -p <new db>

Sliding Sidebar

About Me

About Me

Hello, my name is Dũng (Johnny). Welcome to my blog.

As I’m a developer, I write about topics related to the field of programming, mainly from a technical point of view. On this blog you’ll find posts which encourage discussion, information about development trends, case studies, reviews, tutorials, tips on how to improve your effectiveness, and anything else that might be fascinating to people from the IT industry.
I love PHP, NodeJS, Java,... and Fullstack.