Linux, a small circle of ape Mysql operation command

Most do programming friends are accustomed to using linux system, then the general development environments to build in the linux environment, today a small circle jerk ape will take you to learn about how to use mysql database linux environment, according to Xiao Bian white a step by step to ah, here to learn about it!

First, connect MySQL

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

1, Example 1: MYSQL connected to the machine.

First, open a DOS window, then enter the directory mysqlbin, then type the command mysql -uroot -p, you lose the password prompt after the carriage return, if just installed MYSQL, super-user root no password, so you can directly enter into the the MYSQL, MYSQL prompt is: mysql>.

2, Example 2: MYSQL connected to the remote host. Assuming that the remote host IP is: 110.110.110.110, the user name is root, password is abc @ 123. Type the following command:

mysql -h110.110.110.110 -uroot -pabc@123

(Note: u and the root can not have spaces, the other is the same)

3, exit MYSQL command: exit (Enter).

Second, change your password

Format: mysqladmin -u username -p password old password new password

1, Example 1: to add a root password ab13. First, enter the directory mysqlbin under DOS, and then type the following command:

mysqladmin -uroot -password ab13

Note: Since the beginning of root without a password, so the -p an old password can be omitted.

2, Example 2: then the root password to djg234.

mysqladmin -uroot -pab12 password djg234

Third, add new users. (Note: different from above, the following environment because MySQL command, so the back with a semicolon as a command terminator)

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

Example 1, add a user password for test1 abc, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First to root user connected to the MySQL, then type the following command:

grant select,insert,update,

delete on *.* to test1@\"%\" Identified by \"abc\";

Example 1 but increased user is very dangerous, you want to know as someone test1 password, then he can log in to your MySQL database on any computer on the internet and you can do whatever data, the solution see Example 2.

Example 2, add a user test2 password is abc, so that he can only log on localhost, and can query the database mydb, insert, modify, delete operations (localhost means the local host, namely that host MySQL database resides) so that users know that the use test2 password, he can not directly access the database from the internet, you can only be accessed through the web page on the MySQL host.

grant select,insert,update,

delete on mydb.* to test2@localhost identified by \"abc\";

If you do not want test2 password, you can resort to a command to eliminate the password.

grant select,insert,update,delete on mydb

.* to test2@localhost identified by \"\";

Four, mysql service operations command

1.linux next start mysql command:

mysqladmin start

/ect/init.d/mysql start (in front of the installation path mysql)

2.linux next restart mysql command:

mysqladmin restart

/ect/init.d/mysql restart (the front of the installation path mysql)

Under the mysql command to close 3.linux:

mysqladmin shutdown

/ect/init.d/mysql shutdown (in front of the installation path mysql)

4. mysql connector on the machine:

Go to the directory mysql \ bin, then type the command mysql -uroot -p, prompt for a password after Enter.

Exit mysql command: exit (Enter)

5. Modify the mysql password:

mysqladmin -u username -p password old password new password

Or enter the command line mysql SET PASSWORD FOR root = PASSWORD ( "root");

6. Add new user. (Note: after the command mysql environment with a semicolon as a command terminator)

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

Such as adding a user test password to 123, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First, for the root user connected to the mysql, and then type the following command:

grant select,insert,update,delete on *.* to " Identified by "123";

Five aspects of the operations related to mysql database

You must first log in to mysql, the related operations are carried out in the mysql prompt, and each command with a semicolon

1, display a list of databases.

show databases;

2, the display library data table:

use mysql; // Open Library

show tables;

3 showing the structure of the data table:

describe 表名;

4, building a database:

create database 库名;

GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

5, built table:

use the library name;

create table table name (field set list);

6, delete the database and delete tables:

drop database library name;

drop table 表名;

7, the empty record in the table:

delete from 表名;

truncate table 表名;

8, display records in the table:

select * from 表名;

9, coded modified

If you want to change the entire mysql encoding formats:

Mysql start time, mysqld_safe command line to join

--default-character-set=gbk

If you want to change the encoding format of a library: Enter the command at the mysql prompt

alter database db_name default character set gbk;

10. rename table

alter table t1 rename t2;

11. Review of the efficiency sql statement

explain < table_name >

例如:explain select * from t3 where id=3952602;

12. The text mode data into the database tables (e.g. D: /mysql.txt)

mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;

Xiao Bian use linux system mysql on here, surely we have learned, almost white should all understand it, if you feel which part of the problem, you can go to a small circle ape to learn about, but also a message to the small series can, ah, I hope everyone in the small ape laps led learning more and also more learned.


Reproduced in: https: //juejin.im/post/5d088b326fb9a07ef20122b0

Guess you like

Origin blog.csdn.net/weixin_34080903/article/details/93181633