Installing and backing up MySQL in Linux

Source: Internet
Author: User
Tags mysql commands
In Linux, MySQL installation and backup and related password recovery still account for the majority of applications. If you are curious about this technology, the following articles will unveil its mysteries. I hope it will help you in this regard. Abstract: This article introduces MySQL installation and data MySQL for the powerful MySQL database.

In Linux, MySQL installation and backup and related password recovery still account for the majority of applications. If you are curious about this technology, the following articles will unveil its mysteries. I hope it will help you in this regard. Abstract: This article introduces MySQL installation and data MySQL for the powerful MySQL database.

In Linux, MySQL installation and backup and related password recovery still account for the majority of applications. If you are curious about this technology, the following articles will unveil its mysteries. I hope it will help you in this regard.

Abstract: This article introduces MySQL installation, data MySQL installation and backup, and password recovery when the password is lost. Unless otherwise stated, the Linux system tested in this article is RedHat9.0.

Oracle helps you gain an accurate insight into each logistics Link

MySQL Installation

The 2nd Redhat 9 discs provide MySQL RPM packages for easy installation. This RPM package has: MySQL-3.23.54a-11.i386.rpm

MySQL-server-3.23.54a-11.i386.rpm

MySQL-devel-3.23.54a-11.i386.rpm

During installation, you can use this disc for installation, or download the latest RPM package from the Internet, and then install it.

The following uses the RPM package as an example to introduce the MySQL installation process. If you have installed MySQL during RedHat installation, you can skip the following installation steps.

Run the rpm-qa | grep MySQL command to check whether MySQL is installed in Linux.

If the system is not installed

Perl-CGI-2.81-88.i386.rpm

Perl-DBI-1.32-5.i386.rpm

Perl-DBD-MySQL-2.1021-3.i386.rpm

MySQL-3.23.54a-11.i386.rpm

MySQL-server-3.23.54a-11.i386.rpm

Why install the Perl rpm package? This is because in RedHat, MySQL requires support from the Perl language to run normally. Therefore, you must install the Perl language and related packages before installing MySQL.

We will install the above five rpm packages according to the installation sequence below.

# Rpm-ivh perl-CGI-2.81-88.i386.rpm

# Rpm-ivh perl-DBI-1.32-5.i386.rpm

# Rpm-ivh MySQL-3.23.54a-11.i386.rpm perl-DBD-MySQL-2.1021-3.i386.rpm

# Rpm-ivh MySQL-server-3.23.54a-11.i386.rpm

Install MySQL in Linux

Now that MySQL has been installed, run the command to start MySQL and check whether it is started.

We can start MySQL in three ways:

Method 1: use the service command to start MySQL

# Service MySQL start

Method 2: Use the MySQLd script to start MySQL:

#/Etc/init. d/mys qld start

Method 3: Use the safe_MySQLd utility to start the MySQL service.

# Safe_MySQLd & // use & to put safe_MySQLd in the background for execution.

Here we use method 2 to start MySQL

We can use the Command service MySQLd status to check whether MySQL has been started, as shown in Figure 4. The "3295" in "pid 3295" is the process number that MySQLd runs, this process number is not fixed, but varies according to the number of processes running in different systems.

MySQL has been installed and started. We can use commands in MySQL to operate our MySQL database.

We can use MySQL-u root-p to access the database. The system will prompt us to enter the password. when MySQL is installed, the password of the root account is blank by default, so we can directly press "enter" to enter our database. We can also use the show databases; command to view the existing databases in the system. See, we can see that the system comes with the MySQL and test databases by default.

To change the MySQL password, run the MySQLadmin command in the format

MySQLadmin-u root-p password. The "password" here is the new password. As shown in, here we set the root password to "public", and the system will prompt us to enter the old password (if MySQL is just installed, the default password is blank ).

There are still many Mysql commands. We cannot introduce them one by one here. Interested readers can refer to the Mysql Command manual.

MySQL installation backup

Our database needs to be backed up frequently. The common backup method of Mysql database is to use the utility mysqldump. The command format is as follows:

# Mysqldump [options] database [tables]

The parameter description is as follows:

Options: indicates the option of mysqldump. You can find it through mysqldump-help.

Database: indicates the database to be backed up.

Tables: indicates the table to be backed up. If no table is specified, the entire database is backed up.

We used mysqldump to back up the mysql library that comes with mysql, and used

Ll command to view the backup file.

Let's take a look at the recovery after the backup, as shown in Figure 9. We create a new database bak and then import the mysql. bak file we just backed up to this database.

Create a bak Database

Import mysql. bak to the bak Database

Mysql password recovery

If Mysql is not accessed for a period of time, you may forget the access password. What should I do? reinstall mysql? The cost is too high. Here we will introduce two methods to restore the password.

Method 1: Because the Mysql password is stored in the user table in the mysql database, we only need to copy and overwrite the user table with the known password.

In Linux, there are three user table files in the/var/lib/mysql/directory: user. frm, user. MYD, and user. MYI. They represent:

User. frm // user Table Style File

User. MYD // user table data file

User. MYI // user table index file

For the sake of insurance, we will first install and back up the three user table related files MySQL,

Change mysql password

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.