Install mysql5.7 in linux environment

 

Download the installation package

mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

 

Enter the mysql installation directory and unzip the installation package

[root@c1 ~]# cd /usr/local/

[root@c1 ~]# cd /usr/local/

[root@c1 local]# tar -xzvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

Create soft link

ln -s mysql-5.7.18-linux-glibc2.5-x86_64 mysql

Create mysql user group and mysql user

[root@c1 local]# groupadd mysql

[root@c1 local]# useradd -r -g mysql -s /bin/false mysql

add environment variable

export PATH=$PATH:/usr/local/mysql/bin

Create data directory

[root@c1 mysql]# mkdir data

Enter the mysql directory to set permissions

[root@c1 mysql]# chown -R mysql .

[root@c1 mysql]# chgrp -R mysql .

Initialize the database

[root@c1 mysql]# bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize —user=mysql

2017-04-22T03:35:46.881957Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-22T03:35:47.316012Z 0 [Warning] InnoDB: New log files created, LSN=45790

2017-04-22T03:35:47.416436Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2017-04-22T03:35:47.501745Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c61db9e6-270c-11e7-9df4-0800274f6f8e.

2017-04-22T03:35:47.503551Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-04-22T03:35:47.504380Z 1 [Note] A temporary password is generated for root@localhost: d762:DwgnS*l

 

Remember the temporary root password  

d762:DwgnS*l

Since the mysql directory we installed is not the installation directory we specified, we need to modify /etc/my.cnf

Specify basedir and datadir directories

[mysqld]

datadir = / var / lib / mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

 

change into

 

[[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/usr/local/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

[client]

socket=/usr/local/mysql/mysql.sock

port=3306

 

Copy start mysql service script

[root@c1 mysql]# cp -a support-files/mysql.server  /etc/init.d/mysqld

start the service

[root@c1 mysql]# /etc/init.d/mysqld start

Starting MySQL.                                            [  OK  ]

 

mysql console login

[root@c1 bin]# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18

 

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> set passord =password('123456');

ERROR 1193 (HY000): Unknown system variable 'passord'

mysql> set password=password('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

change Password 

Change can use the root account to access the database remotely

[root@c1 bin]# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18

 

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> set passord =password('123456');

ERROR 1193 (HY000): Unknown system variable 'passord'

mysql> set password=password('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

Refresh permissions

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

Finally add the startup service

chkconfig —level 35 mysqld on 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326311098&siteId=291194637