mysql basics - basic command line operations

1. Basic command line operations

1. Command line connection

mysql -u username -p password

mysql -uroot -proot   连接数据库

insert image description here
2. Modify the mysql password

update  mysql.dor  set authentication_string=password('root') where user='root'and Host='localhost';   //修改用户密码

3. Refresh permissions

flush privileges;  --刷新权限

4. View all databases

 show databases; --查看所有数据库

insert image description here

5. Use a database (use database name)

 use dormitory; -- 切换数据库

insert image description here
6. View the tables in the database

show tables;

insert image description here
7. View information in a table (describe table name;)

describe admin;

insert image description here
8. Create database
create database database name;

create database dor;

insert image description here

insert image description here

9. Exit the connection

exit  --退出连接

10. Notes

--空格 注释内容    代表单行注释(sql本身的注释)
# 注释内容
/*注释内容*/   sql的多行注释

Second, the four languages ​​of the
database DDL database definition language
DML database operation language
DQL database query language
DCL database control language

3. Operate the database (understand)
Operate the database > Operate the table in the database > Operate the fields of the table in the database

mysql关键字不区分大小写

3.1 Operating the database
(Note:
①The content in [] can be written or not, if it is written, the [] should be removed
②The code written in the view can not be written;)
1. Create a database

create database [if not exists] dor1;

insert image description here
2. Delete the database

drop database 【if exists】 hellp

3. Use a database

-- 如果表名或字段名是一个特殊字符,就需要带tab键上面的字符`
如:
	use `school`;

4. View all databases

show databases 

Guess you like

Origin blog.csdn.net/Silly011/article/details/123667505