MySQL management tips for beginners

Source: Internet
Author: User

Last time we introduced: suitableBeginnersMySQL learning notes table operation example. Here we will introduce someMySQL databaseManagement experience, Next let's take a look at this part of the content.

In Windows, MySQL exists as a service. Before using mysql, make sure that the service has been started and the net start MySQL command is not enabled. In Linux, the "/etc/rc. d/init. d/mysqld start" command is available. Note that the initiator must have administrator privileges.

The newly installed MySql contains a root account with a blank password and an anonymous account, which poses a major security risk. For some important applications, we should improve the security as much as possible, here, you should delete anonymous accounts and Set passwords for root accounts. You can run the following command:

 
 
  1. use mysql;  
  2. delete from User where User="";  
  3. update User set Password=PASSWORD('newpassword') where User='root'; 

If you want to restrict the logon terminal used by the User, you can update the Host field of the corresponding User in the User table. After making the above changes, restart the database service, at this time, the following commands can be used for Logon:

 
 
  1. mysql -uroot -p;  
  2. mysql -uroot -pnewpassword;  
  3. mysql mydb -uroot -p;  
  4. mysql mydb -uroot -pnewpassword;  
  5.  

The preceding command parameters are part of common parameters. For details, refer to the documentation. Here, mydb is the name of the database you want to log on.

In development and practical applications, users should not only use root users to connect to the database. Although it is convenient to use root users for testing, it will bring significant security risks to the system, it is not conducive to the improvement of management technology. We grant the most appropriate database permissions to the users used in an application. For example, a user who only inserts data should not be granted the permission to delete data. MySql User management is implemented through the User table. There are two common methods to add new users. One is to insert the corresponding data rows in the User table and set the corresponding permissions; the second is to use the GRANT command to create a user with certain permissions. The common usage of GRANT is as follows:

 
 
  1. grant all on mydb.* to NewUserName@HostName identified by "password" ;  
  2. grant usage on *.* to NewUserName@HostName identified by "password";  
  3. grant select,insert,update on mydb.* to NewUserName@HostName identified by "password";  
  4. grant update,delete on mydb.TestTable to NewUserName@HostName identified by "password";  
  5.  

To GRANT the user the ability to manage permissions on the corresponding object, you can add the with grant option after GRANT. For users inserted into the User table, use the Password function to update and encrypt the PASSWORD field to prevent unauthorized users from stealing the Password. Users who do not need permissions should be cleared, and those who pass the permissions should be revoked in a timely manner. To REVOKE permissions, you can update the corresponding fields in the User table or use the REVOKE operation.

Global Management permissions:

FILE: read and write files on the MySQL server.

PROCESS: displays or kills service threads of other users.

RELOAD: RELOAD Access Control tables and refresh logs.

SHUTDOWN: Shut down the MySQL service.

Database/data table/data column permissions:

Alter: Modify existing data tables (such as adding/deleting columns) and indexes.

Create: Create a new database or data table.

Delete: Delete table records.

Drop: delete a data table or database.

INDEX: Create or delete an INDEX.

Insert: Add Table records.

Select: displays/searches for table records.

Update: Modify existing records in the table.

Special permissions:

ALL: allow anything (same as root ).

USAGE: Only logon is allowed. Other operations are not allowed.

This article introduces the MySQL management experience that is suitable for beginners. I hope this introduction will be helpful to you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.