I. Installation
Go to the MySQL official website at http://dev.mysql.com/downloads/mysql/, and download mysqlinstallable dmgversion
For example:Mac OS X ver. 10.7 (x86, 64-bit), DMG Archive
The downloaded file is: mysql-5.6.10-osx10.7-x86_64.dmg
1. Click
2. Click to install
After the installation, the system preference settings, such as the following, will appear:
3. Click this icon to pop up the dialog box.
Click Start MySQL server to start MySQL
2. Open the terminal and define the MySQL alias
Enter the alias command
Alias MySQL =/usr/local/MySQL/bin/MySQL
Press enter and enter
Alias mysqladmin =/usr/local/MySQL/bin/mysqladmin
3. Set the password of the MySQL Root Account
Mysqladmin-u Root Password initial password
2. If you need to modify the password, run the following command:
Mysqladmin-u root-P password latest Password
Enter the password. Enter the old password and press Enter.
4. Connect to the database
Mysql-u root-P
Then, enter the password and the initial password set in step 3.
2. If you log on to the MySQL database on the remote host
Mysql-H host address-u user name-P User Password
5. Perform common MySQL database operations
Note: The following operations are all performed. After connecting to the database, you can enter the MySQL environment. The commands executed later must contain a semicolon (;).
First, use root permission to connect to MySQL
Mysql-u root-P
Then, enter the root password.
1. Add new users
The format is as follows:
Grant operation permission on database. * To username @ login host address identified'Password';
Grant a user (with the user's login password) on a host the permission to perform certain operations on a database.
(1) For example, on any host ("%"), the user (username: test1, password: ADC) has the permission to perform any operation on all databases (very dangerous)
Grant all privileges on *. * To test1@"%"Identified"ABC";
All privileges indicates the query, insert, modify, and delete permissions: Select, insert, update, and delete.
The preceding commands are equivalent:
GrantSelect, Insert, update, delete on *. * To test1@"%"Identified"ABC";
Then refresh the permission
Flush privileges;
(2) For example, authorize the user on the local host to operate on the database
Create a database(For example, openfire)
Create Database openfire;
Grant the operation permission of the local host user (username: Test2, password: 123) to access the database (Database Name: openfire)
Grant all privileges on openfire. * To Test2 @ localhost identified"123";
Flush privileges;
Then, you can use a new user to access the openfire database.
2. Update the password of the specified account (username: test1, new password: 1234)
Update mysql. User SET Password = PASSWORD ('1234') Where user ="Test1"And host ="Localhost";
3. delete a user
Use the MySQL database first
Use MySQL;
Delete a local user (test7) from the user table in the MySQL database)
Delete from user where user ="Test7"And host ="Localhost";
4. Display commands
(1) display the list of all databases
Show databases;
Only two databases are initialized, MySQL and test.
Note: MySQL system information is stored in the MySQL database. For example, you can use this database to modify the password and add new users.
(2) open a database (such as the database: openfire)
Use openfire;
(3) display all tables in this database
Show tables;
(4) display the structure of a table (Table1)
Describe Table1;
(5) database creation
Create Database database name;
(6) create a table
Use Database Name; Create Table Name (field setting list );
(7) delete a database
Drop database database name;
(8) delete a table
Drop table name;
(9) clear records in the table
Delete from table name;
(10) display records in the table
Select* From table name;
6. log out of MySQL
Exit
7. Start and Stop MySQL
Start
/Usr/local/MySQL/share/MySQL. Server start
Stop
/Usr/local/MySQL/bin/mysqladmin-u root-P Shutdown
Enter the root password