MySQL entry of common commands

MySQL entry of common commands


My Blog [my blog]: New blog Zero cloud - Yun Yi campus plan

You can learn Oh! ! !


First to enliven the atmosphere! Nothing to write about, do not spray GangsterHere Insert Picture Description


1, connect Mysql

Format: mysql -h host address -u user name -p User password

1, is connected to the machine on MYSQL.(Mysql must first set the environment variable)

mysql -u root -p

Just installed MYSQL, root has no password, so you can directly enter into the MYSQL

After the successful landing is shown below:

mysql>

2, exit MYSQL command: exit


2, change passwords

Format: mysqladmin -u username -p password old password new password
Suppose username: root Old Password: xingly new password: xingly.cn

mysqladmin -u root -p xingly password xingly.cn


NOTE: The following commands need to add; (semicolon), analog C / Java Bar
Remember that on the line, do not ask why!
Here Insert Picture Description


3, add new users

Format: grant select on database * to username @ log on the host identified by "password."

1, add a user: test1, password: abc, get the highest authority - can operate on all databasesVery not recommend this

grant select,insert,update,delete on . to [email=test1@”%]test1@”%[/email]” Identified by “abc”;

2. Add a user: test1, password: abc, get all the permissions - you can only operate a local server

grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by “abc”;

Here Insert Picture Description


4.1 Creating a database

命令:create database <数据库名>

例1:建立一个名为xingly的数据库

create database xingly;


4.2 显示数据库

命令:show databases (注意:最后有个s)

mysql>show databases

注意:为了不再显示的时候乱码,要修改数据库默认编码。以下以UTF-8编码页面为例进行说明:

修改MYSQL的配置文件:my.ini里面修改default-character-set=utf-8


4.3 删除数据库

命令:drop database <数据库名>

例如:删除名为xingly的数据库

mysql> drop database xingly;


4.4 连接数据库

命令: use <数据库名>
例如:这里使用名为:xingly的数据库

mysql> use xingly;

屏幕提示:Database changed 就连接成功了


4.5 当前选择的数据库

命令:mysql> select database();
1.显示MYSQL的版本

mysql> select version();

2.显示当前时间

mysql> select now();

3.显示字符串

mysql> SELECT “welecome to my CSDN-blog!”;

4.当计算器用

select ((4 * 4) / 10 ) + 25;


5、备份数据库

命令:mysqldump -u 用户名 -p 数据库名 > 导出的文件名

1.导出整个数据库—导出文件默认是存在mysql\bin目录下

mysqldump -u user_name -p123456 database_name > xingly.sql


Here Insert Picture DescriptionHere Insert Picture Description

关注新零云博客,获取原创PDF!

Here Insert Picture Description

More original tutorial please scan code Watch blog
I will own original technology series, self-study method lessons learned have been organized into PDF with a table of contents for easy download the study, and continuously updated, you can exchange the contents of the PDF with me not only learning technology, better exchange of learning together! Growing, all in addition to coding! Video tutorials available to everyone for free!

Published 47 original articles · won praise 51 · views 20000 +

Guess you like

Origin blog.csdn.net/xg987599519/article/details/104233690