Initializing MySQL Database

Source: Internet
Author: User

Whether you are compiling the installation, the binary installation, or the yum,rpm, the MySQL is initialized to be used.

Below to introduce the next initialization of the installation of MySQL, before installation to prepare the My.cnf file Oh ~ ~ How to configure MY.CNF, you can read my other article.

However, it is important to note that the release version and version number, some parameters will be different or not available, will cause initialization failure, the need to go to initialize the data directory to view the Mysql.err, to see if there is a problem with the parameter, and then block, re-initialized again.

-Pre-steps, have been done to ignore

Mkdir-p/data/mysql/datagroupadd mysqluseradd-g mysql-s/sbin/nologin mysqlchown-r mysql.mysql/data/mysql/datamkdir/ Data/mysql/tmpchown-r mysql.mysql/data/mysql/tmp/

-Note: Before operation, make sure there are no other MySQL release disturbances, especially Yum installed and RPM installations,

Rpm-e--nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64rpm-e--nodeps mysql.x86_64

Additional instructions:--nodeps is not to check dependencies, do not be afraid, even if you have to rely on your own installation package are sure to have, do a soft connection is good

Ln-s/usr/local/mysql/lib/libmysqlclient.so.20/usr/lib64/libmysqlclient.so.18

-------------------------This split line, whatever version you want to do, OH!--------------------------

-5.6 and previous version initialization steps (including 5.6)

Make sure the MySQL process is stopped

Service MySQL Stop

Ensure that the initialized data directory has no data

rm-rf/data/mysql/data*

Execute initialization script, add parameters, remember to edit my.cnf first.

/usr/local/mysql/scripts/mysql_install_db--defaults-file=/usr/local/mysql/my.cnf--basedir=/usr/local/mysql/-- Datadir=/data/mysql/data--user=mysql >/dev/null 2>&1

Start MySQL

Service MySQL Start

Initialize password

/usr/local/mysql/bin/mysqladmin-u root password ' new password '

#初始化完成, try to log in

/usr/local/services/mysql/bin/mysql-uroot-p ' New password '

------------------------------I'm a split line---------------------------------

-After 5.7 in a new way

Make sure the MySQL process is stopped

Service MySQL Stop

Ensure that the initialized data directory has no data

rm-rf/data/mysql/data*

Executes the initialization command, specifies Defaults-file, and must be placed first, so remember to edit the MY.CNF

Mysqld--defaults-file=/usr/local/mysql/my.cnf--initialize

Check the initial password (password information at the end), 5.7 of the initialization is very special, will automatically generate a password, you can not log in without this password, unless you enter the security mode break password, or the parameter--initialize replaced--initialize-insecure, After initialization, you can avoid password logon.

Sed-n '/password/p '/data/mysql/data/mysql.err ..... A temporary password is generated for [email protected]: gvedtgxdz1-,

Change the master permission of the data directory, initialization does not change this is the main problem, do not change the words will not start

Chown-r mysql:mysql/data/mysql/data/

Start MySQL

Service MySQL Start

Password also to initialize, although the initialization of the database has a password, you can log in directly, but the initialization has not really completed, or will error, prompting you to change the password

Mysql-uroot-p ' gvedtgxdz1-, '

It must be the following change, or not change

mysql> alter user ' root ' @ ' localhost ' identified by ' 123 ';mysql> set password for ' root ' @ ' localhost ' =password (' 123 ') );

It's time to initialize, try the new password you set to log in.

Mysql-uroot-p ' 123 '

-Extended reading: MySQL 5.7 added two fields password_last_changed, password_lifetime to improve security policy, can set parameter default_password_lifetime to extend the lifespan

ALTER USER ' root ' @localhost ' PASSWORD EXPIRE INTERVAL; ALTER USER ' root ' @ ' localhost ' PASSWORD EXPIRE never; ALTER USER ' root ' @ ' localhost ' PASSWORD EXPIRE DEFAULT;

---------------------------------I'm a split line too-----------------------------------

Is it really over after the initial initialization? It's better to be a safe reinforcement.

Securely harden MySQL database (best after initialization)

Remove any unrelated admin users and empty passwords for admin users, there is a need to re-open

Delete from Mysql.user where user= "root" and host!= "localhost";d elete from Mysql.user where user= "root" and password= "; fl Ush privileges;

Delete Test library, because this library by default is everyone has permission to read and write, there is a vulnerability

drop database test;

Delete the table information that holds the database because there is no database information.

Delete from mysql.db;

In fact, 5.7 of the security do better, above these do not make a difference is not big, but do more step is safer.

Initializing MySQL Database

Related Article

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.