• notice
  • Congratulations on the launch of the Sought Tech site

MySQL utility command

1) Connect to MYSQL:
Format: mysql-h host address-u Username-p User Password
1, Example 1: Connect to MYSQL on this machine
First open the DOS window, and then enter mysql under the bin directory under the installation directory, for example: D:\mysql\bin, and then type the command mysql-uroot-p, and you will be prompted to enter the password after pressing Enter.If MYSQL has just been installed, the super user root does not have a password, so you can enter MYSQL directly by pressing Enter.The prompt of MYSQL is: mysql>
2, Example 2: Connect to a remote host MYSQL
Assume that the remote host’s IP is 10.0.0.1, the user name is root, and the password is 123.Then type in the following command:
mysql-h10.0.0.1-uroot-p123
(Note: u and root need not add spaces, the other is the same)
3.Exit MYSQL command
exit (Enter)
(2) Modify password:
Format: mysqladmin-u username-p old password password new password
1, example 1 : Add a password 123 to root.First enter the directory C:\mysql\bin under DOS, and then type the following command:
mysqladmin-uroot-password 123
Note: Because root does not have a password at the beginning, the-p old password can be omitted.
2, Example 2: Change the password of root to 456
mysqladmin-uroot-pab12 password 456
(3) Add a new user: (Note: different from the above, The following are commands in the MYSQL environment, so they are followed by a semicolon as the end of the command)
Format: grant select on database.* to username@Login host identified by "password"
Example 1, Add a user test1 password to abc, so that he can log in on any host, and have query, insert, modify, and delete permissions for all databases.First connect to MYSQL as the root user, and then type the following command:
grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";
But the user added in Example 1 It is very dangerous.If someone knows the password of test1, then he can log in to your mysql database on any computer on the Internet and do whatever you want with your data.The solution is shown in Example 2.
Example 2.Add a user test2 password to abc, so that he can only log in on localhost, and can query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, where the MYSQL database is located Host), so that even if the user knows the password of test2, he cannot directly access the database from the internet, and can only access it through the web page on the MYSQL host.
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
If you don't want test2 to have a password, you can type another command to delete the password.
grant select,insert,update,delete on mydb.* to test2@localhost identified by "";
(4) Display commands
1.Display database list:
show databases;
At the beginning, there were only two databases: mysql and test.The mysql library is very important.It contains MYSQL system information.When we change the password and add users, we actually use this library for operations.
2, display the data table in the library:
use mysql;//open the library
show tables;
3, display the structure of the data table:
describe table name;
4 , Build a database:
create database library name;
5, create a table:
use library name;
create table table name (list of field settings);
6, delete database and delete Table:
drop database library name;
drop table table name;
7, clear the records in the table:
delete from table name;
8, display the records in the table:
select * from table name;

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+