1.检查环境并关闭selinux
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# cat /etc/selinux/config
SELINUX=disabled
2.官网【mysql.com】下载部署,上传,解压
[root@localhost ~]# md5sum mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mkdir -p /usr/local/app/
[root@localhost app]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/app/
[root@localhost app]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm #安装依赖
[root@localhost app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
3.创建mysql用户和数据目录并修改权限
[root@localhost app]# useradd mysql
[root@localhost app]# mkdir /data/mysql -p
[root@localhost app]# chown -R mysql.mysql /usr/local/app/*
[root@localhost app]# chown -R mysql.mysql /data/* #注意/data下面是否有其他目录或文件
4.数据库初始化
[root@localhost bin]# /usr/local/app/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/app/mysql --datadir=/data/mysql
2024-10-14T08:20:48.422961Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-10-14T08:20:48.652291Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-10-14T08:20:48.699275Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-10-14T08:20:48.776503Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 37d22bcb-8a05-11ef-b56c-000c292ea57c.
2024-10-14T08:20:48.777090Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-10-14T08:20:48.777591Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
5.添加环境变量(最好在第三步之前添加,可以直接用mysqld初始化)
vim /etc/profile
export PATH=/usr/local/app/mysql/bin/:$PATH
[root@localhost mysql]# source /etc/profile
6.书写默认配置文件
[root@localhost etc]# cat my.cnf
[mysqld]
user=mysql
basedir=/usr/local/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
7.直接启动mysql
[root@localhost support-files]# pwd
/usr/local/app/mysql/support-files
[root@localhost support-files]# /usr/local/app/mysql/support-files/mysql.server start
[root@localhost support-files]# /usr/local/app/mysql/support-files/mysql.server status
SUCCESS! MySQL running (9428)
8.配置systemctl管理mysql
[root@localhost system]# cat /etc/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@localhost bin]# systemctl daemon-reload
[root@localhost system]# systemctl start mysql.service
[root@localhost system]# systemctl status mysql.service
[root@localhost system]# ps aux | grep mysql
mysql 9574 0.1 9.1 1117776 171104 ? Ssl 17:33 0:00 /usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 9632 0.0 0.0 112708 980 pts/1 R+ 17:36 0:00 grep --color=auto mysql
[root@localhost system]#
[root@localhost system]#
[root@localhost system]# netstat -anlp | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 9574/mysqld
unix 2 [ ACC ] STREAM LISTENING 49697 9574/mysqld /tmp/mysql.sock
unix 3 [ ] STREAM CONNECTED 49671 9574/mysqld
9.测试进入数据库
[root@localhost data]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
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> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
mysql>
10.进程占用
2024-10-14T08:54:03.995393Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2024-10-14T08:54:05.001701Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2024-10-14T08:54:05.001729Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2024-10-14T08:54:06.012634Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2024-10-14T08:54:06.012654Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
[root@localhost support-files]# ps -aux | grep mysql
mysql 8988 0.0 9.1 1117480 171400 pts/1 Sl+ 16:57 0:00 /usr/local/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 9056 0.0 0.0 112708 980 pts/0 R+ 17:06 0:00 grep --color=auto mysql
[root@localhost support-files]#
[root@localhost support-files]#
[root@localhost support-files]# kill -9 8988