MYSQL深入浅出系列--库的基本访问
安装方面就不多说了,先从简单的开始分享,说说WINDOWS版
这个下载太慢了
https://dev.mysql.com/downloads/mysql/
可以考虑在我的百度云盘上下载链接:https://pan.baidu.com/s/1IvfzLfN5u44o4TY5H22t8g
提取码:s1u7
安装好后如下
接下来调用这个界面,输入密码,进入控制台,开始系列操作
不过还是建议在cmd下操作更靠谱一些
cd 到bin目录下
C:\Users\45240>cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql -uroot -p 是直接到root用户下
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 8.0.17 MySQL Community Server - GPL
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
接下来说说一些基本操作,好歹知道自己是谁,自己从哪里来,到哪里去。。。。。
- 看看都有哪些数据库
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
±-------------------+
6 rows in set (0.00 sec)
- 查看当前用户属于哪个数据库
mysql> select database();
±-----------+
| database() |
±-----------+
| NULL |
±-----------+
1 row in set (0.00 sec)
root默认不属于任何一个数据库
mysql> use mysql
Database changed
这样就加进去了
mysql> select database();
±-----------+
| database() |
±-----------+
| mysql |
±-----------+
1 row in set (0.00 sec)
- 查看当前用户
mysql> select user();
±---------------+
| user() |
±---------------+
±---------------+
1 row in set (0.00 sec)
建用户
mysql> create user ‘ljb’ identified by ‘ljb’;
Query OK, 0 rows affected (0.01 sec)
4.对用户授权
mysql> grant dba to ljb;
ERROR 3523 (HY000): Unknown authorization ID dba
@%
mysql> grant all privileges on . to ljb;
Query OK, 0 rows affected (0.00 sec)
5.切换用户和DB
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -uljb -pljb
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.17 MySQL Community Server - GPL
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> select user() ;
±--------------+
| user() |
±--------------+
±--------------+
1 row in set (0.00 sec)
6.建表等对象
mysql> create table t(id int);
Query OK, 0 rows affected (0.04 sec)