Mysql 5.7. 17 Login to mysql after installation tutorial

  • 2021-07-01 08:24:43
  • OfStack

The installation of mysql-5. 7.17 is introduced below the article, and you can refer to it. Let's introduce the tutorial of logging in to mysql after installing Mysql 5.7. 17. Let's take a look at it.

Random passwords are generated when you run./bin/mysqld initialize to initialize the database. Example:


[Note] A temporary password is generated for root@localhost: Wtng#?e&S5,-

The password in the example is Wtng #? e & S5,-, login to mysql for the first time, 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, modify the my. cnf file under root user, skip the password and log in directly. After logging in to mysql, use mysql command line to change the password. This method is also suitable for forgetting mysql password and needing to change the password.


$ vi /etc/my.cnf
  [mysqld] Configuration Zone Add: 
  skip-grant-tables
$ service mysqld restart

At this time, you can log in directly and then change your password.


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

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

Method of installing mysql-5. 7.17 (centos-6. 8-minimal) with source code

Official documents

http://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html

Preparatory work

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


$ yum install  In fact, in fact, the 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 it to a directory, which needs to be specified when installing mysql. In addition, mysql official website provides 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 unzip 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


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
0

Step 3 Initialize


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
1

Versions 5.7. 6 and above initialize the database with./bin/mysqld--initialize;
After initialization, a random password is generated. Example: [Note] A temporary password is generated for root @ localhost: Wtng #? e & S5,-.
. /bin/mysql_ssl_rsa_setup requires openssl support to enable data volume ssl connections and requires one step of configuration.

4. Configuration files


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
2

Modified part:


basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock

5. Start the script


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
4

Modified part:


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
5

There are two startup scripts, /usr/local/mysql/bin/mysqld_safe and/usr/local/mysql/support-files/mysql. server (i.e./etc/init. mysqld). When the mysqld is started, mysqld_safe starts simultaneously, and mysqld_safe monitors the mysqld service, logs errors, and restarts the mysqld when it stops due to a failure.

6. Start the mysqld service


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
6

To set boot boot:


$ /usr/local/mysql/bin/mysql -uroot -p'Wtng#?e&S5,-'
7

Related articles: