web123456

Linux installation and deployment operation steps

CentOS9. The difference between CentOS8

Setting up power-on is a bit different from previous versions

1. Installation package preparation

MySQLDownload address:/downloads/file/?id=480751

1. Upload the installation to /opt/software/

[appview@salve1 software]$ ll
Total dosage 384624
-rw-rw-r-- 1 appview appview 393852364 5moon   6 22:21 mysql-8.0.13-linux-glibc2.12-x86_64.

2. Uninstall the built-in Mysql-libs

rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps

3. Unzip to the specified directory

[root@salve1 software]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64. -C /usr/local/
[root@salve1 software]# cd /usr/local/
[root@salve1 local]# ll
Total dosage 0
drwxr-xr-x. 2 root root   6 5moon  11 2019 bin
drwxr-xr-x. 2 root root   6 5moon  11 2019 etc
drwxr-xr-x. 2 root root   6 5moon  11 2019 games
drwxr-xr-x. 2 root root   6 5moon  11 2019 include
drwxr-xr-x. 2 root root   6 5moon  11 2019 lib
drwxr-xr-x. 2 root root   6 5moon  11 2019 lib64
drwxr-xr-x. 2 root root   6 5moon  11 2019 libexec
drwxr-xr-x  9 root root 172 5moon   6 22:36 mysql-8.0.13-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 5moon  11 2019 sbin
drwxr-xr-x. 5 root root  49 3moon  24 01:32 share
drwxr-xr-x. 2 root root   6 5moon  11 2019 src
[root@salve1 local]#
[root@salve1 local]# mv mysql-8.0.13-linux-glibc2.12-x86_64   mysql-8.0.13
[root@salve1 local]# cd mysql-8.0.13/
[root@salve1 mysql-8.0.13]# ll
Total dosage 448
drwxr-xr-x  2 root root    4096 5moon   6 22:36 bin
drwxr-xr-x  2 root root      86 5moon   6 22:36 docs
drwxr-xr-x  3 root root     266 5moon   6 22:35 include
drwxr-xr-x  6 root root    4096 5moon   6 22:36 lib
-rw-r--r--  1 7161 31415 335809 10moon  7 2018 LICENSE
-rw-r--r--  1 7161 31415 101807 10moon  7 2018 
drwxr-xr-x  4 root root      30 5moon   6 22:35 man
-rw-r--r--  1 7161 31415    687 10moon  7 2018 README
-rw-r--r--  1 7161 31415    700 10moon  7 2018 
drwxr-xr-x 28 root root    4096 5moon   6 22:36 share
drwxr-xr-x  2 root root      90 5moon   6 22:36 support-files
[root@salve1 mysql-8.0.13]#
[root@salve1 mysql-8.0.13]#
[root@salve1 mysql-8.0.13]# mkdir data
[root@salve1 mysql-8.0.13]#
​

4. Create user groups and user passwords, and change directory group

[root@salve1 mysql-8.0.13]# groupadd mysql
[root@salve1 mysql-8.0.13]# useradd -g mysql mysql
[root@salve1 mysql-8.0.13]#
[root@salve1 mysql-8.0.13]# pwd
/usr/local/mysql-8.0.13
[root@salve1 mysql-8.0.13]# chown -R mysql:mysql /usr/local/mysql-8.0.13
[root@salve1 mysql-8.0.13]#
​

5. Initialize the information, generate the initial password, and use it for reporters and others.

[root@salve1 mysql-8.0.13]# cd bin/
[root@salve1 bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql-8.0.13 --datadir=/usr/local/mysql-8.0.13/data/ --initialize
2024-05-06T14:50:12.080585Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.13/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 33055
2024-05-06T14:50:16.464122Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: (>Rhe5opF*fh   #### (Initial Password (>Rhe5opF*fh)2024-05-06T14:50:18.814045Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.13/bin/mysqld (mysqld 8.0.13) initializing of server has completed
[root@salve1 bin]#

2. The watershed between cents8 and previous versions and CentOS Stream 9 begins here

1.Cents8 and previous versions are set up so that it's OK, but CentOS Stream 9 is a bit different from this one
[root@salve1 mysql-8.0.13]# cp  ./support-files/ /etc//mysql
[root@salve1 mysql-8.0.13]# vim  /etc//mysql
####### Modify it to your own pathbasedir=/usr/local/mysql-8.0.13
datadir=/usr/local/mysql-8.0.13/data
[root@salve1 mysql-8.0.13]# chmod +x /etc//mysql
[root@salve1 mysql-8.0.13]# chkconfig --add mysql

2. Configuration

[root@salve1 mysql-8.0.13]# vim /etc/
​
#### Add the following​
[mysqld]  
basedir=/usr/local/mysql-8.0.13
datadir=/usr/local/mysql-8.0.13/data  
port = 3306  
character-set-server=utf8mb4  
# Other configuration items...

3. Start mysqld

[root@salve1 mysql-8.0.13]# service mysql start
Starting MySQL... SUCCESS!
[root@salve1 mysql-8.0.13]#

5. Check the status

[root@salve1 mysql-8.0.13]# service mysql status
 SUCCESS! MySQL running (36456)
[root@salve1 mysql-8.0.13]#

2. CentOS Stream 9 boot and self-start settings

1. Add mysql command to the service

[root@salve1 mysql-8.0.13]# ln -s /usr/local/mysql-8.0.13/bin/mysql /usr/bin
[root@salve1 mysql-8.0.13]#
[root@salve1 mysql-8.0.13]# ll /usr/bin/mysql
lrwxrwxrwx 1 root root 33 5moon   6 23:27 /usr/bin/mysql -> /usr/local/mysql-8.0.13/bin/mysql

2. ConfigurationMySQL

Create and configure MySQL configuration files. This file is usually located in/etc/In the directory.

vim /etc/

[mysqld]  
basedir=/usr/local/mysql-8.0.13
datadir=/usr/local/mysql-8.0.13/data  
port = 3306  
character-set-server=utf8mb4  
# The default storage engine that will be used when creating a new tabledefault-storage-engine=INNODB
​
explicit_defaults_for_timestamp=true
​
#Case sensitive settings 0: case sensitive, 1: case insensitivelower_case_table_names=1
​
#Solve mysql connection slow (201906181517)skip-name-resolve
3. In CentOS Stream 9, you can use itsystemctlCommand to manage services and set up power-on.

usesystemdService unit file: Create a new service unit file, e.g./etc/systemd/system/

Define the MySQL service start command, stop command, user, group, etc. in this file.

vim /etc/systemd/system/

[Unit]  
Description=MySQL Server  
After=   
  
[Install]  
WantedBy=  
  
[Service]  
User=mysql  
Group=mysql  
ExecStart=/usr/local/mysql-8.0.13/bin/mysqld --defaults-file=/etc/  
ExecStop=/usr/local/mysql-8.0.13/bin/mysqladmin --user=root shutdown  
Restart=on-failure

Note: The aboveExecStartandExecStopThe commands and paths in it need to be adjusted according to your actual installation.

4. Enable and start the service
  • usesystemctlCommand to enable service:systemctl enable mysqld

  • Start the service:systemctl start mysqld

  • Now, the MySQL service should be set to power on and start.

5. Testing and Verification
  • Restart your CentOS Stream 9 system and check if the MySQL service starts automatically.

  • You can usesystemctl status mysqldCommand to view the status of the MySQL service.

    [root@hdp001 mysql-8.0.13]# systemctl status mysqld
    ●  - MySQL Server
         Loaded: loaded (/etc/systemd/system/; enabled; preset: disabled)
         Active: active (running) since Sat 2024-05-25 17:43:10 CST; 5min ago
       Main PID: 14940 (mysqld)
          Tasks: 37 (limit: 22828)
         Memory: 370.8M
            CPU: 2.391s
         CGroup: //
                 └─14940 /usr/local/mysql-8.0.13/bin/mysqld --defaults-file=/etc/
    ​

3. Login test

1. Note: CentOS 8 has encountered this problem before and now CentOS Stream 9, but CentOS Stream 9 has installed yum install libncurses* to log in, and the following error is reported. CentOS 8 can successfully log in
[root@salve1 mysql-8.0.13]# mysql -uroot -p
mysql: error while loading shared libraries: .5: cannot open shared object file: No such file or directory
#### Log in to report the above error, solution[root@salve1 mysql-8.0.13]# yum install libncurses*
Stream 9 extra operations

Because our yum has been installed, but the dependencies are still missing, we look for whether there is a corresponding dependency, and we found .5, which has no error. I also encountered this problem when I tested the environment to install doris to configure mysql client, and I couldn't figure it out. . . . . . .

Later, the solution was solved through GPT, including the operation of CentOS Stream 9 power-on and self-start

[root@hdp001 mysql-8.0.13]# find / -name \* 2>/dev/null
/var/lib/docker/overlay2/0ff41823ead084037731de6f1c3e30844a9ade2dcaf423229a186141cd3f5932/diff/lib/x86_64-linux-gnu/.5
/var/lib/docker/overlay2/0ff41823ead084037731de6f1c3e30844a9ade2dcaf423229a186141cd3f5932/diff/lib/x86_64-linux-gnu/.5.9
/var/lib/docker/overlay2/6e717c4e3a18e2f0f2fa5715955e0fa2aa92b8e2b03ed4fb1e4db12b9e116f99/diff/lib/x86_64-linux-gnu/.5
/var/lib/docker/overlay2/6e717c4e3a18e2f0f2fa5715955e0fa2aa92b8e2b03ed4fb1e4db12b9e116f99/diff/lib/x86_64-linux-gnu/.5.9
/usr/lib64/.6
/usr/lib64/.6.2

Next useSoft connectionMake .5 point to .6.2, then log in to verify successfully.

ln -s /usr/lib64/.6.2 /usr/lib64/.5

4. Login verification and password modification

[root@salve1 mysql-8.0.13]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
​
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
​
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
​
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
​
###### Modify passwordmysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.03 sec)
​
mysql> use mysql;
mysql> select user, host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
|  | localhost |
|     | localhost |
|         | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
​
##### Modify remote connectionmysql> update user set host="%" where user="root";
Query OK, 1 row affected (0.08 sec)
Rows matched: 1  Changed: 1  Warnings: 0
​
mysql> select user, host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
|  | localhost |
|     | localhost |
|         | localhost |
+------------------+-----------+
#### refreshmysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#### quitmysql> quit;
Bye
[root@salve1 mysql-8.0.13]#