Linux installation MySQL5.7.26 installation


Enter the download page:
insert image description here
insert image description here

download link

https://dev.mysql.com/downloads/mysql/5.7.html#downloads
Unzip after the download is complete

tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar 

insert image description here
move and rename

mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql

insert image description here

Create mysql user groups and users and modify permissions

|1|	groupadd mysql
|2|	useradd -r -g mysql mysql

Create a data directory and grant permissions

|1| mkdir -p  /data/mysql  					#创建目录
|2| chown mysql:mysql -R /data/mysql  		#赋予权限

insert image description here
Configure my.cnf
to use vim to modify the last wq command to save or modify directly by the client

vim /etc/my.cnf

The content is modified as follows (if the above datadir and basedir are specified by yourself, you need to pay attention that basedir, datadir, and symbolic-links need to be under the current mysqld, otherwise an error will be reported when starting)

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

Initialize the database

1. Enter the bin directory of mysql

cd /usr/local/mysql/bin/

2. Initialization

./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

If an error is reported when using the initialization command: ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file:
libaio needs to be installed at this time

yum install -y libaio  //安装后再使用初始化命令就OK了

3. View password

cat /data/mysql/mysql.err

It is possible that this cannot be found. At this time, look at the log printed directly after the mysql initialization command in the previous step. There is the initial password
insert image description here

Start mysql and change the root password

First place mysql.server in /etc/init.d/mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

start up! ! !

|1| service mysql start 
|2| ps -ef|grep mysql

insert image description here
**Here shows that mysql has been successfully installed! !

change Password

First log in to mysql, the previous one is randomly generated, and the password is the one found before.

./mysql -u root -p   #bin目录下

insert image description here
Follow the next three steps and log in again.

SET PASSWORD = PASSWORD('123456');     //设置密码
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; 
FLUSH PRIVILEGES;                      //刷新

insert image description here
At this time, if you use a remote connection...you will find that you cannot connect.
insert image description here
The following three commands are mainly executed here (login to the database first)

use mysql                                            #访问mysql库
update user set host = '%' where user = 'root';      #使root能再任何host访问
FLUSH PRIVILEGES;                                    #刷新

insert image description here
insert image description here
If you do not want to use the mysql command in the bin directory every time, execute the following command

ln -s  /usr/local/mysql/bin/mysql    /usr/bin

Guess you like

Origin blog.csdn.net/qq_46150411/article/details/118531705