MySQL databases can be said to be one of the most common and commonly used databases of DBAs. To facilitate your use, MySQLDBA summarizes some of the most common and frequently used experience and skills of MySQL databases, share with you!
MySQL databases can be said to be one of the most common and commonly used databases of DBAs. To facilitate your use, the old MySQL DBA summarizes some of the most common and frequently used experience and skills of MySQL databases, share with you!
MySQL databases can be said to be one of the most common and common databases for DBAs. The wide application of MySQL also adds more people to the ranks of them. The following are some of the most common and frequently used MySQL Databases summarized by the old MySQL DBA!
When using MySQL databases, database backup is the most common and important. So we will first introduce database backup. Database Backup is also a formal database backup method. It shares the same concept with other database servers, but have you ever thought that MySQL will have a simpler backup method using the file directory, and it's always better (this method has not been verified in the official documentation. We call it a test now ).
Purpose:Back up a mysql database TestA in the hostA host and restore it to the hostB host.
Test environment:
Operating System: WinNT4.0, Mysql3.22.34, and phpMyAdmin 2.1.0;
Install the mysql database in hostA and create a TestA database;
The mysql database is installed on the hostB and does not have the TestA database.
Procedure:
1. Start phpMyAdmin to check the database list in HostA and HostB, and there is no TestA database in HostB;
2. Find the mysql installation directory in HostA and the database directory data;
3. In my test environment, the directory is C: mysqldata;
4. Find the subdirectory C: mysqldataTestA of the corresponding database name;
5. paste and copy the file to the Data directory of HostB, which is the same as that of the Data Directory of HostB Mysql;
6. Refresh the phpMyAdmin of HostB and check the database list. We can see that TestA has appeared, and the query and modification operations are normal. The Backup recovery is successful.
Conclusion:Mysql databases can be saved, backed up, and restored in the form of files. You only need to restore the corresponding file directories without using other tools for backup.
Format: mysql-h host address-u user name-p User Password
1. Connect to MYSQL on the local machine.
First, open the DOS window, enter the directory mysqlbin, then type the command mysql-uroot-p, and press enter to prompt you to enter the password. If you have just installed MYSQL, super User root has no password, so press enter to enter MYSQL. The MYSQL prompt is: mysql.
2. Connect to MYSQL on the remote host. Assume that the IP address of the remote host is 110.110.110.110, the user name is root, and the password is abcd123. Enter the following command:
Mysql-h110.110.110.110-uroot-pabcd123)
3. exit MYSQL command: exit (Press ENTER ).
1. If you forget the extra points after you press Enter when making the command, you don't have to repeat the command. You just need to press a semicolon to press Enter. That is to say, you can divide a complete command into several lines and use a semicolon as the end mark to complete the operation.
2. You can use the cursor to bring up or down the previous commands. However, an old MySQL version I used earlier does not support this feature. I am using a mysql-3.23.27-beta-win.
1. display the Database List:
Show databases;
At the beginning, there were only two databases: mysql and test. The MySQL database contains the MYSQL system information. We change the password and add new users to use this database for operations.
2. display the data tables in the database:
Use mysql; // open the database. If you have learned FOXBASE, you will not be unfamiliar with it.
Show tables;
3. display the data table structure:
Describe table name;
4. database creation:
Create database name;
5. Create a table:
Use Database Name;
Create table Name (field setting list );
6. Delete databases and tables:
Drop database name;
Drop table name;
7. Clear records in the table:
Delete from table name;
8. Display records in the table:
Select * from table name;
Drop database if exists school; // Delete if SCHOOL exists
Create database school; // create a database SCHOOL
Use school; // open the SCHOOL library
Create table teacher // create table TEACHER
(
Id int (3) auto_increment not null primary key,
Name char (10) not null,
Address varchar (50) default 'shenzhen ',
Year date
); // Table creation ends
// Insert fields as follows
Insert into teacher values ('', 'glengang ', 'shenzhen Zhongyi', '2017-10-10 ');
Insert into teacher values ('', 'jack', 'shenzhen Zhongyi ', '2017-12-23 ');
Note: In the table in progress (1), set the ID to a numeric field of 3: int; (2) and make it automatically add one: auto_increment for each record. It cannot be blank: not null and set it as the primary key; (3) set NAME to a character field with a length of 10; (4) set ADDRESS to a 50-character field, the default value is Shenzhen. What is the difference between varchar and char? It will only be discussed later. (5) set YEAR as the date field.
If you type the preceding command at the MySQL prompt, debugging is not convenient. You can write the above commands into a text file as they are. SQL, then copy to c :\\, and enter the directory \ mysql \ bin in DOS status, and then type the following command:
Mysql-uroot-p password c: \ school. SQL
If it succeeds, no display is displayed for a blank row. If there is an error, a prompt is displayed. (The preceding command has been debugged. You only need to remove the // annotation to use it ).
6. Change the password
Format: mysqladmin-u username-p old password New password
1. Add a password ab12 to the root user. First, enter the directory mysqlbin in DOS, and then type the following command:
Mysqladmin-uroot-password ab12
Note: because the root account does not have a password at the beginning, the old-p password can be omitted.
2. Change the root password to djg345.
Mysqladmin-uroot-pab12 password djg345
(Note: Unlike the above, the following commands in the MySQL environment are followed by a semicolon as the command Terminator)
Format: grant select on database. * to username @ login host identified by \ "password \"
Example 1: Add a user named "test1" with the password "abc" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MySQL, and then type the following command:
Grant select, insert, update,
Delete on *. * to test1 @ \ "% \" Identified by \ "abc \";
However, the User Added in Example 1 is very dangerous. If someone knows the password of test1, then he can log on to your MySQL database on any computer on the internet and do whatever he wants for your data. For the solution, see Example 2.
Example 2: Add a user named "test2" with the password "abc" so that the user can only log on to localhost, you can also query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the host where the MySQL database is located), so that the user knows the password of test2, he cannot access the database directly from the internet, but can only access the database through the web pages on the MySQL host.
Grant select, insert, update,
Delete on mydb. * to test2 @ localhost identified by \ "abc \";
If you do not want test2 to have a password, you can run another command to remove the password.
Grant select, insert, update, delete on mydb
. * To test2 @ localhost identified by \ "\";
These are some common MySQL database operations and techniques.