First, log in to MySQL
1. Start:
MySQL boot file in the/ETC/INIT.D directory, start running the following command
/etc/init.d/mysql start
2. Stop:
/usr/bin/mysqladmin-u root-p shutdown
3. Login:
MySQL [-u username] [-h host] [-p password] [dbname]
Here we introduce the structure of MySQL: Database---table. The last dbname refers to the table name, you can specify which table in the database you want to use, or you want to specify the table after you log on to the database. The following I specify is the scraping database
You can also not specify a database login, log in and then specify the database name: Use + database name
Ii. several important directories of MySQL
Database files, configuration files and command files in separate directories
1. Database directory:/var/lib/mysql/
2. Configuration file:/usr/share/mysql (Mysql.server command and its configuration file)
3. Related commands:/usr/bin/(mysql admin mysql dump etc command)
4. Startup script:/etc/rc.d/init.d (startup script file mysql directory)
Iii. Common Commands
1. Displaying the database
show databases; "must be added at the back"; ' Every command in MySQL is; End
The MYQL library is very important, there are MySQL system information, change password and new users, are in the related table to operate.
2. Displaying tables in the database
First use the library: using MySQL
Show tables in the database: show tables
3. Display the structure of the table
describe table name;
4. Show Records
SELECT * FROM table name
5. Create a new database
Create database + databases name;
6. Build a table
Use library name;
CREATE TABLE table name (field settings list);
7. Add Records:
INSERT INTO
8. Modify the Record
Update
9. Deleting records
Delete
10. Delete a table/database
Drop database + library name;
drop table + list name;
Iv. User Settings
Grant SELECT on database. * To User name @ login host identified by "password"
Mysql> Grant Select,insert,update,delete on * * to [e-mail protected] "%" identified by "123";
Example 1 added user is very dangerous, if you know the user_1 password, then he can be on any computer on the Internet to log on to your MySQL database and your data to do whatever you like, the solution is shown in Example 2.
Example 2, the addition of a user user_2 password of 123, so that the user can only log on localhost, and the database AAA can query, insert, modify, delete operations (localhost refers to the local host, that is, the MySQL database host), This allows the user to use the password that knows user_2, and he cannot access the database directly from the Internet, only through the MySQL host to operate the AAA library.
Mysql>grant Select,insert,update,delete on aaa.* to [e-mail protected] identified by "123";
With the new user if you can't log in MySQL, log in with the following command:
Mysql-u user_1-p-H 192.168.113.50 (-H followed by the IP address of the host to be logged in)
MySQL operation under Linux