Linux installation MySQL5.7.26 installation
Enter the download page:
![insert image description here](https://img-blog.csdnimg.cn/20210706224705294.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTUwNDEx,size_16,color_FFFFFF,t_70#pic_center)
![insert image description here](https://img-blog.csdnimg.cn/20210706224839432.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTUwNDEx,size_16,color_FFFFFF,t_70)
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
move and rename
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
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 #赋予权限
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
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
**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目录下
Follow the next three steps and log in again.
SET PASSWORD = PASSWORD('123456'); //设置密码
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES; //刷新
At this time, if you use a remote connection...you will find that you cannot connect.
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; #刷新
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