Linux-Centos_7.9_2009离线编译安装MySQL8.0.33
软件包下载地址:
centos7.9:https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/
MySQL Community Server: https://dev.mysql.com/downloads/mysql/
1 、清理安装环境
[root@localhost ~]# yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
[root@localhost ~]# userdel -r mysql
[root@localhost ~]# rm -rf /etc/my*
[root@localhost ~]# rm -rf /var/lib/mysql
2、解压,移动位置并重新命名
[root@localhost ~]# tar xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# mv mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
3、创建mysql用户组和用户并修改权限
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
4、创建目录并赋予权限
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown mysql:mysql -R data
5、配置my.cnf文件
[root@localhost ~]# vi /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
user = mysql
basedir = /usr/local/mysql #指定安装目录
datadir = /usr/local/mysql/data #指定数据存放目录
socket = /tmp/mysql.sock
character_set_server = utf8
6**、初始化数据库**
[root@localhost mysql]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2023-09-27T08:07:24.927768Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 1632
2023-09-27T08:07:24.928864Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2023-09-27T08:07:24.935384Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-09-27T08:07:26.105121Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-09-27T08:07:28.025338Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: De055.bppbi&
7、将mysql.server放置到/etc/init.d/mysql中
[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost bin]# ls -l /etc/init.d/mysql
-rwxr-xr-x 1 root root 10576 Sep 27 16:08 /etc/init.d/mysql
8、启动数据库
[root@localhost bin]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
.. SUCCESS!
9、登录数据库并修改初始密码
[root@localhost bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> exit
Bye
10、用systemctl管理mysql服务:
[root@localhost bin]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
Active: active (exited) since Wed 2023-09-27 16:29:34 CST; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 1989 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
Sep 27 16:29:34 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Sep 27 16:29:34 localhost.localdomain mysql[1989]: Starting MySQL SUCCESS!
Sep 27 16:29:34 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
Sep 27 16:29:35 localhost.localdomain mysql[1989]: 2023-09-27T08:29:35.086651Z mysqld_safe A mysqld process already exists
[root@localhost bin]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
Active: active (exited) since Wed 2023-09-27 16:29:34 CST; 17s ago
Docs: man:systemd-sysv-generator(8)
Process: 1989 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
Sep 27 16:29:34 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Sep 27 16:29:34 localhost.localdomain mysql[1989]: Starting MySQL SUCCESS!
Sep 27 16:29:34 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
Sep 27 16:29:35 localhost.localdomain mysql[1989]: 2023-09-27T08:29:35.086651Z mysqld_safe A mysqld process already exists
、扩展
设置环境变量;可以直接使用mysql相关命令:
[root@xingdian ~]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@xingdian ~]# source /etc/profile
[root@localhost ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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.
########配置远程连接
mysql>
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)