Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of installation backup and password recovery of Mysql in Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "Linux system Mysql installation backup and password recovery method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux system Mysql installation backup and password recovery method" bar!

Installation of Mysql

The second CD of Redhat 9 provides Mysql's RPM package, which is very easy to install. The 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 the CD for installation, or you can install it from the latest RPM package on the Internet.

Take the installation of the RPM package as an example to introduce the installation process of Mysql. If you have already installed Mysql when installing Red Hat, you can skip the following installation steps.

We can use the rpm-qa grep mysql command to detect whether the system has Mysql installed.

If the system is not installed, change the

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 rpm package for Perl? This is because in RedHat, Mysql requires the support of the Perl language to function properly, so you need to install the Perl language and its related packages before installing mysql.

We install the above five rpm packages in the following installation order.

# 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

Now that mysql is installed, we can use the command to start Mysql and verify that 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, which can use relevant parameters

# safe_mysqld& / / using & means that safe_mysqld is executed in the background.

Here we use method two to start Mysql

We can use the command service mysqld status to detect whether mysql has been started, as shown in figure 4, where the "3295" in the return message "pid 3295" is the process number that mysqld is running, which is not fixed, but varies according to the number of processes running on different systems.

Mysql has been installed and started, and we can use the 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 installation, the default root account password is empty, so we can directly enter our database by typing "enter". We can also use the show databases; command to view existing databases in the system. As shown in figure 5, we can see that mysql and test are included by default in the system.

If we want to change the password of mysql, we can use the mysqladmin command in the format of

Mysqladmin-u root-p password password, the "password" here is the password we want to set. As shown in the following figure, here we set the password of root to "public" and we will be prompted to enter the old password (if mysql has just been installed, the default password is empty).

There are many Mysql commands, and it is impossible for us to introduce them all here. Interested readers can refer to Mysql's command manual.

Backup of Mysql

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

# mysqldump [options] database [tables]

The meaning of its parameters is:

Options: the option that represents mysqldump, which can be found through mysqldump-help.

Database: represents the database to be backed up

Tables: represents the table to be backed up, and if no table is specified, the entire database is backed up.

We backed up the mysql library that comes with mysql using mysqldump and used the

Ll command to view the backup file.

Let's take a look at the recovery after backup. As shown in figure 9 and figure 10, we create a new database bak, and then import the mysql.bak file we just backed up into this database.

Password recovery of Mysql

Mysql does not visit every once in a while, maybe you will forget your access password, what should you do when you reinstall mysql? This cost is too high, here we introduce two ways to recover passwords.

Method 1: because the Mysql password is stored in the user table in the database mysql, we just need to copy the user table of the known password to overwrite it.

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

User.frm / / user table style file

User.MYD / / user table data file

User.MYI / / user table index file

To be on the safe side, let's back up the files related to these three user tables first.

Then we copy three files of the user table in the mysql library that knows the password, and we can see the six user table files with ls.

At this point, we only need to restart the mysql service to access the Mysql database with a known password.

The command to restart is: service mysql restart or

/ etc/init.d/mysql restart

Now we can access the Mysql database with a known password.

Method 2:

The first method is to recover the password on the premise that the password of another Mysql database is known. If there is no such a Mysql database with known password, how can we recover it? We use a method described in the Mysql Chinese reference manual, which is divided into several steps:

1: send a kill command to mysqld server to turn off mysqld server (not kill-9). The file where the process ID is stored is usually in the same directory as MYSQL's database.

Killall-TERM mysqld / / you must be a root user of UNIX or the one you are running

Only the equivalent user on SERVER can perform this operation.

2: use the `--skip-grant-tables parameter to start mysqld. (LINUX / usr/bin/safe_mysqld-- skip-grant-tables, c:mysqlinmysqld-- skip-grant-tables)

3: then you can log in to mysqld server without a password, and the password of Mysql is the same as when it was first installed, which is empty. Now we can use the method in figure 6 to change the password of mysql with mysqladmin.

4: load the permission table. You can use mysqladmin flush-privileges to refresh the permission table

5: log in with the new password.

Mysql is a powerful one, which needs to be mastered in practice. This paper introduces the installation of Mysql and the most basic commands for accessing Mysql and modifying passwords. Finally, it introduces two methods to recover passwords for the loss of Mysql passwords. I hope it will be helpful to all of you.

Thank you for reading, the above is the content of "installation backup and password recovery method of Mysql in Linux system". After the study of this article, I believe you have a deeper understanding of the installation backup and password recovery method of Mysql in Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report