Install mysql linux 5.7.22

Decompress package

1
2
3
4
cd /usr/local
tar -xzvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
rm -f mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz mysql

Group & User

1
2
3
4
5
6
7
8
9
10
11
12
# linux account
groupadd mysql
useradd -r -g mysql mysql

# dataspace
cd /usr/local/mysql
mkdir data

# privilege
cd /usr/local
chown -R mysql mysql/
chgrp -R mysql mysql/

Init

1
2
3
4
5
6
7
8
cd /usr/local/mysql/bin

./mysqld --initialize
--user=mysql
--basedir=/usr/local/mysql/
--datadir=/usr/local/mysql/data/
--lc_messages_dir=/usr/local/mysql/share
--lc_messages=en_US

remember the init root password

Setting

1
2
3
4
5
6
7
8
9
10
11
12
vi /etc/my.cnf
# modify

basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
port=3306
character-set-server=utf8
explicit_defaults_for_timestamp=true

#datadir=/var/lib/mysql
#socket=/usr/local/mysql/data/mysql.sock
user=mysql

Service

1
2
3
4
5
6
7
8
9
10
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql

# add setting
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/

chmod +x /etc/init.d/mysql
chkconfig --add mysql

privilege

1
2
3
4
5
cd /usr/local/mysql/bin
./mysql -u root -p
set password=password("root");
grant all privileges on *.* to'root' @'%' identified by 'root';
flush privileges;

Exception

1
mysqld: Can't create/write to file '/tmp/ibgXpx9Y' (Errcode: 13 - Permission denied)

if the /tmp dirctory have no permission:

1
chmod 777 /tmp

https://blog.csdn.net/NB6063/article/details/80417319
https://blog.csdn.net/shaochenshuo/article/details/51375905