View the system version:
cat /etc/centos-release CentOS Linux release 8.0.1905 (Core)
Download the resource package to the mysql official website according to the system version
Version: Linux-Generic
Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive
Download and install
Install Upload Toolkit
yum install -y lrzsz
upload files:
rz
unzip files:
xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar
Move files:
mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql
Create the data directory:
mkdir data
Create mysql user group and mysql user
groupadd mysql
useradd -g mysql mysql
Change mysql directory permissions
chown -R mysql.mysql /usr/local/mysql/ or chown -R mysql . chgrp -R mysql .
Because my.cnf will not be automatically generated and created manually:
touch /etc/my.cnf
Modified content:
vim my.cnf
[mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /usr/local/mysql/mysql.sock character-set-server=utf8 port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] socket = /usr/local/mysql/mysql.sock default-character-set=utf8
ESC save
: wq exit
Change directory permissions
chown -R mysql:mysql /usr/local/mysql
Initialize the database:
method one:
bin / mysqld --initialize --user = mysql --basedir = / usr / local / mysql --datadir = / usr / local / mysql / data // Initialize the database
Method 2:
/usr/local/mysql/bin/mysqld --initialize --user=mysql
The second way I use:
/usr/local/mysql/bin/mysqld --initialize --user=mysql A temporary password is generated for root@localhost: x2+JhQ1=?n/W
The temporary password after A temporary password should be remembered: x2 + JhQ1 =? N / W
Configure MySql service:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod + x /etc/init.d/mysqld // seems to report an error, continue to execute the following
chmod + x / etc / rc .d / init.d / mysqld
chkconfig --add mysqld
chkconfig --list mysqld
Configure global environment variables:
vi /etc/profile Add the following two lines of configuration at the bottom of the profile file, save and exit export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib export PATH
Execute after saving and exiting:
source /etc/profile
Start the MySql service:
service mysql start
或
/usr/local/mysql/support-files/mysql.server start
View the MySql startup status:
service mysql status
Password login:
mysql -uroot -p password
change Password:
update user set authentication_string='' where user='root';
FLUSH PRIVILEGES;
Re-login:
alter user 'root'@'localhost' identified by '新密码';
FLUSH PRIVILEGES;
Set up to log in remotely
mysql>use mysql mysql>update user set host='%' where user='root' limit 1; mysql>flush privileges;
Firewall installation:
yum install firewalld
Open port 3306:
firewall -cmd --permanent --add-prot=3306/tcp
Add under / etc / my.cnf [mysqld] skip-grant-tables Password-free login
service mysqld restart