Install MySQL on alicloud server

1. Download MySQL installation package

Using Huawei image download, the download speed will be faster. The following is the link of Huawei image: https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/

The version I selected is 8.0.27, which can be downloaded   mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz   file

 

 

2. Upload the installation package to Linux  

It is recommended to use visualization tools to upload files, which will be more convenient for future operations. I use Xshell. If there is no installation tool, you can install the tool first and upload it to / usr/local/temp

3. Decompression

Because the end of the file is xz, the decompression command is also different

xz -d  mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz //First unzip the file into mysql-8.0.17-linux-glibc2.12-x86_64.tar
tar xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar  //Then unzip mysql-8.0.17-linux-glibc2.12-x86_64.tar

4. Move folder

  Copy the extracted folder to / usr/lcoal/mysql

cp -r  mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql

5. Configuration (the following operations are performed under / usr/lcoal/mysql)

5.1 creating users and user groups

groupadd mysql
useradd -r -g mysql mysql

5.2 the purpose of modifying permissions is to ensure that the owner of the MySQL directory installed is the MySQL user and the group belongs to the MySQL group, that is, the user group MySQL and the user MySQL have operation permissions

chown -R mysql .  //You can't lose the backSpace+spot
chgrp -R mysql .  //You can't lose the backSpace+spot

5.3 initializing the database

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mydata

5.4 obtain the initial password after initialization and write it down with Notepad

grep 'temporary password' /var/log/mysqld.log

 

  5.5 generating configuration files

vim /etc/my.cnf

Fill in the following contents in the configuration file

[mysqld]
    basedir = /usr/local/mysql   
    datadir = /usr/local/mydata
    socket = /usr/local/mysql/mysql.sock
    port = 3306
   sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 [client]
   socket = /usr/local/mysql/mysql.sock

5.5 configuring MySQL services

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql

5.6 configuring environment variables

Open the / etc/profile environment variable configuration file

vim /etc/profile

Fill in the following at the end of the environment variable configuration file

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/lib

Make environment variables effective

source /etc/profile

6. Start MySQL

service mysql start

7. Change the initial password

7.1 enter the initial password and log in to MySQL

mysql -u root -pl1O"("sQqniilE  //Note that there is no space after p, and the password is followed directly. If there are parentheses in the password, you need to add \. The escape parentheses are readable, or double quotation marks are used for escape

7.2 change password

alter user'root'@'localhost' identified by '092333'; #You need a semicolon at the end because it is an operation database

8. Open remote service

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges; //Refresh permissions

9. Open alicloud 3306 port

 

9.1 open alicloud console, click Security Group in network and security on the left, and then click configuration rules on the right

9.2 in the entry direction, click Add manually or add quickly to modify according to the gourd's gourd, set port 3306 / 3306, and the authorization object 0.0.0/0 means that all hosts can access the port specified by the server. Just save it

 

 

Tags: Linux

Posted on Mon, 06 Dec 2021 16:30:18 -0500 by MP145