Linux MySQL 终端操作

  1. 进入mysql数据库

    1
    #mysql -uroot -proot
  2. 创建mysql user

    1
    2
    MariaDB [(none)]> create user 'stock'@'localhost' identified by 'stock';
    Query OK, 0 rows affected (0.00 sec)
  3. 查询mysql用户

    1
    2
    3
    4
    5
    6
    7
    8
    MariaDB [(none)]> SELECT User,Host FROM mysql.user;
    +-------+-----------+
    | User | Host |
    +-------+-----------+
    | root | localhost |
    | stock | localhost |
    +-------+-----------+
    2 rows in set (0.00 sec)
  4. 授予mysql用户权限

    1
    2
    MariaDB [(none)]> GRANT ALL ON stock.* TO 'stock'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
  5. 使用show语句查找数据库

    1
    2
    3
    4
    5
    6
    7
    8
    9
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)
  6. 创建数据库stock

    1
    2
    MariaDB [(none)]> create database stock;
    Query OK, 1 row affected (0.00 sec)
  7. 选择创建的数据库

    1
    2
    MariaDB [(none)]> use stock;
    Database changed
  8. 使用show语句查找数据库中的表

    1
    MariaDB [stock]> show tables;
  9. 删除创建的数据库

    1
    2
    MariaDB [(none)]> drop database stock;
    Query OK, 0 rows affected (0.00 sec)
  10. 删除表

    1
    2
    mysql> drop table sequelizemeta;
    Query OK, 0 rows affected (0.01 sec)
  11. 查询表结构

    1
    mysql> desc t_records;
  12. 清除表记录

    1
    mysql> delete from t_records;
  13. 修改数据库账号密码

1
mysqladmin -uroot -p123456 password 123

参考链接

  1. 什么是 MySQL 索引?,by 小灰.
  2. mysql修改用户密码的方法及命令,by 剩余价值.