MYSQL Tutorial: database operations _ MySQL

Source: Internet
Author: User
MYSQL Tutorial: database operations 1. connect to the database server

$./Mysql-h host_name-u user_name-p

-H host_name (-- host = host_name) indicates the host name of the connected Database. it can be omitted if it is on the local host.

-U user_name (-- user = user_name), database Username. on unix systems, if the system username is the same as the data username, it can be omitted. In windows, you can set the environment variable USER to give the database username, for example, set USER = username.

-P (-- password) provides the database user password. With this option, mysql will prompt you to enter the password. The entered password is displayed as a star to ensure security. You can also enter the password directly after-p (no space is allowed between-p and the password), but this is not safe and is not recommended.

After the connection is successful, the mysql database server displays some welcome information. Then you can use the mysql> use database_name command to open the specified database.

This article is organized and published by the Web teaching network! Please indicate the source for reprinting. thank you!

$./Mysql-h host_name-u user_name-p database_name command can directly open the specified database.

2. update the user password

Mysql> update user set password = passowrd ('your passowrd ') where host =' % ';

Refresh permission settings: mysql> flush privileges;

3. the order in which MySQL reads configuration files

My. cnf is the configuration file of the MySQL database. it exists in multiple places, in the/etc directory, both the data directory and the user's main directory. The options in different locations have different scopes. The following describes the order and role of MySQL to read configuration files.

The order in which mysql reads configuration files:

/Etc/my. cnf Global options.

DATADIR/my. cnf Server-specific options.

Defaults-extra-file The file specified with the -- defaults-extra-file option.

~ /. My. cnf User-specific options.

4. reset the MySQL administrator password

Sometimes we forget the password of the database administrator because of the reason or long time, so that we are locked out of the MySQL server. The MySQL server provides a way to reset the password on the server. The operations on windows and linux/unix platforms are slightly different. The following describes the operations:

On Linux/Unix platforms:

Use % kill-term pid to shut down the server, and use-TERM information to allow the server to write data in memory to the disk before closing. If the server does not respond, we can use the % kill-9 PID to force the process to be deleted, but we do not recommend this. Data in the memory is not written to the disk, resulting in incomplete data. If you use the mysql_safe script to start the MySQL server, the script will monitor the running status of the server and restart the server when it is terminated. Therefore, if you need to disable the server, terminate the process first, then terminate the mysqld process.

Use the -- skip-grant-tables parameter to start the MySQL Server. then, the MySQL Server does not use the permission table to verify the connection operation. You can connect to the server without providing the root password and obtain the root permission.

% Mysqld_safe -- skip-grant-tables &

Run the following command to log on to the server and reset the password:

% Mysql-u root

# Connect to the server without a password

Mysql> use mysql

Mysql> set password for 'root' @ 'localhost' = password ('password ');


There are three ways to change the password of a MySQL server account. you can refer to the related content in the daily Database Management chapter in this note. In this environment, changing the password using mysaladmin does not seem to work. you are prompted to enter the password.

Shut down the server and start the server in normal mode.

On windows:

Log on to the server with an administrator account and disable the MySQL database server.

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.