Install on Centos8

  1. First download the binary packageMysql - 8.0.23 - Linux - glibc2.12 - x86_64. Tar. XzAnd unpack.
Mkdir /usr/local/mysql/mysql-8.0.23 # mysql is installed in tar -xvf ` mysql - 8.0.23 - Linux - glibc2.12 - x86_64. Tar. Xz ` / usr/local/mysql/mysql - 8.0.23 CD/usr/local/mysql/mysql - 8.0.23Copy the code
  1. Add user to MySQL and specify user group.
groupadd mysql
useradd -r -g mysql mysql
Copy the code
  1. Create in the installation directorydataDirectory.
CD/usr/local/mysql/mysql - 8.0.23 mkdir dataCopy the code
  1. Create a folder to store it insockFile and assign permissions to the folder. The folder I created is in the installation directory.
CD /usr/local/mysql-8.0.23 mkdir conf mkdir conf/mysql chmod 777 conf/mysqlCopy the code

Before this step, I saw that someone said to put it under/TMP, but/TMP is a temporary folder and data will not be stored for long. MySQL will not be able to start over time. Therefore, / TMP is not recommended. I did it myself, or I wouldn’t have reinstalled it.

  1. in/etcCreate a configuration filemy.cnfAnd configure related information.
  • The socket directory is the folder created in Step 4
  • Basedir is the installation path
  • Datadir is in the installation directorydatafolder
  • The last of theskip-grant-tablesNote that the password is not required for future login. Note this line after changing the password
[mysql]
default-character-set=utf8
socket=/ usr/local/mysql/mysql - 8.0.23 / conf/mysql/mysql. The sock

[mysqld]
port=3306
user=mysql
socket=/ usr/local/mysql/mysql - 8.0.23 / conf/mysql/mysql. The sock
basedir=/ usr/local/mysql/mysql - 8.0.23
datadir=/ usr/local/mysql/mysql - 8.0.23 / data

max_connections=200

# character-set-server=utf8

default-storage-engine=INNODB

max_allowed_packet=16M

default-authentication-plugin=mysql_native_password

transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1

skip-grant-tables
Copy the code
  1. Change the users and groups in the installation directory tomysql.
chown -R mysql:mysql ./
Copy the code
  1. When MySQL is initialized, it generates a random password (not important because you did not use passwords before, if you do not have no-password enabled, you will use this password to log in), and it will be used in thedataDirectory to create some files.
The. / bin/mysqld - the initialize - user = mysql - basedir = / usr/local/mysql/mysql - 8.0.23 - the datadir = / usr/local/mysql/mysql - 8.0.23 / dataCopy the code

Note to change basedir,datadir to their own path.

  1. in/etc/profileEnvironment variables are configured in the.
MYSQL_HOME=/ usr/local/mysql/mysql - 8.0.23
PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/support-files
export PATH
Copy the code

Making the configuration Effective

source /etc/profile
Copy the code
  1. Start the service and change the password.

To start the service, run the mysql.server command, which is in the support-files directory in the installation path. Therefore, the directory is also configured when you configure environment variables.

mysql.server start # start
mysql -uroot -p # login

# Change password
use mysql;
alter user 'root'@'localhost' identified by 'new passwd';
Copy the code

If an error occurs when changing the password, run Flush Privileges. To change the password.

My.cnf: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart: mysql.server restart

  1. Example Enable remote login.
use mysq;
create user 'root'@'%' identified by 'root';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
alter user 'root'@'%' identified with mysql_native_password by 'your passwd';
flush privileges;
exit;
Copy the code

Restart the service.

  1. Firewall on3306Port.

Check the ports that have been allowed on the firewall.

firewall-cmd --list-ports
Copy the code

If port 3306 is not allowed, port 3306 is allowed.

Firewall -cmd --zone=public --add-port=3306/ TCP --permanent systemctl restart firewalldCopy the code
  • service firewall startEnabling the Firewall
  • service firewall stopDisabling the firewall
  • service firewall restartRestarting the Firewall
  • firewall-cmd --stateViewing the Firewall Status

Here all installation is complete, quickly connected to the server to try!

Install it on Ubuntu

Ubuntu 20.04.2 + MySQL8

Run the following commands as the root user:

Wget https://dev.mysql.com/get/mysql-apt-config_0.8.18-1_all.deb DPKG -i mysql - apt - config_0. 8.18 1 _all. Deb apt update apt install mysql-server [ok.]Copy the code