Cyan Hall C H
CyanHall.com 创建。上次更新:11/25/2020 👉  

1. 命令行登录

    mysql -h localhost -u root -p
  

2. 导入 SQL 文件

    mysql -u username -p database_name < file.sql
  

3. 列出所有数据库

    show databases;
  

4. 列出一个数据库中的所有表

    use [db name];
show tables;
  

5. 列出所有用户

    SELECT User, Host, authentication_string FROM mysql.user;
  

6. 创建用户和数据库

    # Create a user
CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'password';

# Create a database
CREATE DATABASE example_db;

# Grant privileges
GRANT ALL ON example_db.* TO 'db_user'@'localhost';
  

7. 删除用户和数据库

    # Delete database
DROP DATABASE example_db;

# Delete user
DROP USER 'db_user'@'localhost';
  

8. 退出命令行

    quit