超级详细的MySQL数据库常用命令/语法(DDL操作数据库部分)

前言:MySQL数据库命令书写的时候需要注意细节的地方比较多,比如说标点符号,字母是否拼写有误,语法格式是否正确,需要耐心。在书写命令的时候慢慢来,不要急躁,沉得住气,遇到问题了仔细排查。后续会不断更新,原创不易,请多多支持。

------------------------------------------------------------------------------------------------------------------------------

1,登录Mysql数据库(一般有2种方式)

(本地登录)mysql -u用户名 -p密码 
(指定ip登录)mysql -h主机地址 -u用户名 -p密码

1,显式登陆:
mysql -uroot -proot 

其中:-u后边的root为用户名,-p后边的root为密码,
一般来说在安装数据库的过程中设置的账号的和密码都是root,
实际登录的时候以自己的数据库的账号和密码为准。

[root@hadoop10 ~]# mysql -uroot -proot
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 13
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 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> 

--------------------------------------------------------------------------
2,隐式登陆:
先输入:musql -u root -p,按下enter键,再输入root,即可登录。

需要注意的地方是:
显式登录-u和root中间没有空格,
隐式登录两者中间有空格,注意区别。

[root@hadoop10 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 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> 

 2,查询所有数据库的名称

show databases;

3,创建MySQL数据库命令

create database 数据库名称;

4,创建数据库,并指定字符集

create database 数据库名称 character set 字符集名;

5,查询某个数据库的字符集:查询某个数据库的创建语句

show create database 数据库名称;

6,修改数据库的字符集

alter database 数据库名称 character set 字符集名称;

7,删除数据库

drop database 数据库名称;

8,查询当前正在使用的数据库名称

select database();  是一个内置函数

10,使用数据库

use 数据库名称;

猜你喜欢

转载自blog.csdn.net/XFB9750/article/details/131054331