When running ./bin/mysqld -initialize to initialize the database,Will generate random passwords,Example:

[note] a temporary password is generated for [email protected]:wtng #?e&s5,-

In the example, the password is wtng #?e&s5,-. Login to mysql for the first time and use this password.

$/usr/local/mysql/bin/mysql -uroot -p "wtng #?e&s5,-"

After logging in to mysql, set the new password to "mypassword".

mysql>set password=password ("mypassword");

There is another way,Regardless of the initial password,Under the root user, modify the my.cnf file to skip the password and log in directly.After logging in to mysql, use the mysql command line to change the password.This method is also applicable when you forget the mysql password and need to change the password.

$vi /etc/my.cnf
  [mysqld] Configuration area added:
$service mysqld restart

You can log in directly at this time,Then change the password.

$/usr/local/mysql/bin/mysql -uroot
mysql>update user set authentication_string=password ("mypassword") where user="root";

Log out of mysql, modify my.cnf, remove the added skip-grant-tables, restart the mysqld service, and log in with the new password.

How to install mysql-5.7.17 (centos-6.8-minimal) from source

Official document

Ready to work

1. Install wget, gcc, gcc-c++, bison, ncurses, ncurses-devel

$yum install --y wget gcc gcc-c++ bison ncurses ncurses-devel

2. Install cmake

$cd/usr/local/src /
$wget https://cmake.org/files/v3.7/cmake-3.7.1.tar.gz
$tar zxvf cmake-3.7.1.tar.gz
$cd cmake-3.7.1
$./bootstrap&&gmake&&gmake install

3. This version requires boost_1_59_0, download and unzip to a certain directory,Need to specify when installing mysql.In addition, the mysql official website provides a mysql source package containing boost.

$wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
$tar zxf boost_1_59_0.tar.gz
$mv boost_1_59_0/usr/local /

4. Download the mysql source package (excluding boost) and decompress it

$cd/usr/local/src /
$wget https://cdn.mysql.com//downloads/mysql-5.7/mysql-5.7.17.tar.gz
$tar zxvf mysql-5.7.17.tar.gz

Installation process

1. Create users and groups mysql:mysql

$groupadd mysql
$useradd -r -g mysql -s/sbin/nologin mysql

2. Compile and install mysql

$cd /usr/local/src/mysql-5.7.17
$mkdir build
$cd build
$cmake .. \
-dcmake_install_prefix =/usr/local/mysql \
-dsysconfdir =/etc \
-dmysql_datadir =/data/mysql \
-dmysql_user=mysql \
-dmysql_unix_addr =/tmp/mysql.sock \
-dmysql_tcp_port=3306 \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_memory_storage_engine=1 \
-dwith_partition_storage_engine=1 \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci \
-dextra_charsets=all \
-denabled_local_infile=1 \
-dwith_boost =/usr/local/boost_1_59_0
$make &&make install

3. initialization

$chown -r mysql:mysql.
$mkdir -p/data/mysql
$chown -r mysql.mysql/data/mysql
$./bin/mysqld --initialize \
--user=mysql \
--basedir =/usr/local/mysql \
--datadir =/data/mysql
$./bin/mysql_ssl_rsa_setup --datadir =/data/mysql

5.7.6 and above use ./bin/mysqld --initialize to initialize the database;

./bin/mysql_ssl_rsa_setup requires openssl support, which is used to enable data ssl connections, which requires further configuration.

4. Configuration file

$cp support-files/my-default.cnf /etc/my.cnf
$vim! $


basedir =/usr/local/mysql
datadir =/data/mysql

5. Startup script

$cp support-files/mysql.server /etc/init.d/mysqld
$vim! $


basedir =/usr/local/mysql
  datadir =/data/mysql

There are two startup scripts,They are/usr/local/mysql/bin/mysqld_safe and /usr/local/mysql/support-files/mysql.server (ie /etc/init.d/mysqld). When starting mysqld, mysqld_safe starts at the same time,mysqld_safe monitors the mysqld service, records error logs,And restart mysqld when it stops due to a failure.

6. Start the mysqld service

/etc/init.d/mysqld start

To set up startup:

$chkconfig --add mysqld
$chkconfig mysqld on
$service mysqld start
  • Previous Android implements highlighting search list based on RecyclerView
  • Next C # common protocol implementation template and FixedSizeReceiveFilter example (introduction to SuperSocket)