数据库二进制包下载
社区版:
https://dev.mysql.com/downloads/mysql/


新建 数据组和数据库启动用户
groupadd -g 401 mysqluseradd -g 401 -u 401 mysql
设置环境变量
export PATH=/app/mysql/bin:$PATH
[mysql@riyimei ~]$ ls -latotal 20drwx------ 2 mysql mysql 99 Feb 21 10:22 .drwxr-xr-x. 7 root root 135 Feb 21 10:17 ..-rw------- 1 mysql mysql 117 Feb 21 10:19 .bash_history-rw-r--r-- 1 mysql mysql 18 Aug 8 2019 .bash_logout-rw-r--r-- 1 mysql mysql 214 Feb 21 10:21 .bash_profile-rw-r--r-- 1 mysql mysql 231 Aug 8 2019 .bashrc-rw------- 1 mysql mysql 648 Feb 21 10:22 .viminfo[mysql@riyimei ~]$ cat .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/binexport PATH=/app/mysql/bin:$PATH[mysql@riyimei ~]$ . ./.bash_profile
设置文件打开数
建数据库数据存放目录
mkdir -p /data/mysql/3306/{data,redo,binlog,tmp,logs}chown -R mysql:mysql /datachmod -R 755 /data
[root@riyimei 3306]# lltotal 0drwxr-xr-x 2 mysql mysql 6 Feb 21 10:08 binlogdrwxr-xr-x 2 mysql mysql 6 Feb 21 10:08 datadrwxr-xr-x 2 mysql mysql 6 Feb 21 10:08 logsdrwxr-xr-x 2 mysql mysql 6 Feb 21 10:08 redodrwxr-xr-x 2 mysql mysql 6 Feb 21 10:08 tmp[root@riyimei 3306]#
拷贝数据库二进制文件到指定部署目录
[root@riyimei ~]# mkdir /app[root@riyimei ~]# cd /app/[root@riyimei app]# lltotal 646212-rw-r--r-- 1 root root 661718255 Feb 21 10:02 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz[root@riyimei app]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz[root@riyimei app]# lsmysql-5.7.33-linux-glibc2.12-x86_64 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz[root@riyimei app]# ln -s /app/mysql-5.7.33-linux-glibc2.12-x86_64 /app/mysql[root@riyimei app]# lsmysql mysql-5.7.33-linux-glibc2.12-x86_64 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz[root@riyimei app]# lltotal 646212lrwxrwxrwx 1 root root 40 Feb 21 10:03 mysql -> /app/mysql-5.7.33-linux-glibc2.12-x86_64drwxr-x--- 9 root root 129 Feb 21 10:03 mysql-5.7.33-linux-glibc2.12-x86_64-rw-r--r-- 1 root root 661718255 Feb 21 10:02 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz[root@riyimei app]# chown -R mysql:mysql /app[root@riyimei app]#
检查依赖库 libaio
[root@riyimei app]# rpm -qa libaiolibaio-0.3.109-13.el7.x86_64[root@riyimei app]#
添加自定义配置文件 my.cnf
[root@riyimei 3306]# ll /data/mysql/3306/my.cnf-rw-r----- 1 root root 937 Feb 21 10:11 /data/mysql/3306/my.cnf[root@riyimei 3306]#
[root@riyimei 3306]# cat my.cnf[client]default-character-set = utf8port = 3306socket = /data/mysql/3306/tmp/mysql.sock[mysqld]port = 3306character_set_server = utf8server-id = 1socket = /data/mysql/3306/tmp/mysql.sockbasedir = /app/mysqldatadir = /data/mysql/3306/datatmpdir = /data/mysql/3306/tmplog-error = /data/mysql/3306/logs/alert_3306.logpid-file = /data/mysql/3306/tmp/mysql.pidlog-bin = /data/mysql/3306/binlog/mysql-binslow_query_log_file = /data/mysql/3306/logs/slow.logdefault-storage-engine = INNODBinnodb_data_file_path = ibdata1:2G:autoextendinnodb_log_group_home_dir = /data/mysql/3306/redoinnodb_file_per_table = 1[root@riyimei 3306]#
初始化数据库
[mysql@riyimei ~]$ mysqld --defaults-file=/data/mysql/3306/my.cnf --initialize[mysql@riyimei ~]$ ll /data/mysql/3306/data/total 2097220-rw-r----- 1 mysql mysql 56 Feb 21 10:24 auto.cnf-rw------- 1 mysql mysql 1676 Feb 21 10:24 ca-key.pem-rw-r--r-- 1 mysql mysql 1112 Feb 21 10:24 ca.pem-rw-r--r-- 1 mysql mysql 1112 Feb 21 10:24 client-cert.pem-rw------- 1 mysql mysql 1676 Feb 21 10:24 client-key.pem-rw-r----- 1 mysql mysql 436 Feb 21 10:24 ib_buffer_pool-rw-r----- 1 mysql mysql 2147483648 Feb 21 10:24 ibdata1drwxr-x--- 2 mysql mysql 4096 Feb 21 10:24 mysqldrwxr-x--- 2 mysql mysql 8192 Feb 21 10:24 performance_schema-rw------- 1 mysql mysql 1676 Feb 21 10:24 private_key.pem-rw-r--r-- 1 mysql mysql 452 Feb 21 10:24 public_key.pem-rw-r--r-- 1 mysql mysql 1112 Feb 21 10:24 server-cert.pem-rw------- 1 mysql mysql 1676 Feb 21 10:24 server-key.pemdrwxr-x--- 2 mysql mysql 8192 Feb 21 10:24 sys[mysql@riyimei ~]$
查看初始化日志和临时密码
[mysql@riyimei ~]$ tail -n 100 /data/mysql/3306/logs/alert_3306.log2021-02-21T02:24:41.718374Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 20002021-02-21T02:24:42.821456Z 0 [Warning] InnoDB: New log files created, LSN=457912021-02-21T02:24:42.855140Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2021-02-21T02:24:42.880637Z 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: f4eff0a2-73eb-11eb-8080-000c290b2539.2021-02-21T02:24:42.881010Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-02-21T02:24:43.236334Z 0 [Warning] CA certificate ca.pem is self signed.2021-02-21T02:24:43.478305Z 1 [Note] A temporary password is generated for root@localhost: 6NdBc--q3jIg[mysql@riyimei ~]$
启动数据库
[mysql@riyimei ~]$ mysqld_safe --defaults-file=/data/mysql/3306/my.cnf &[1] 19089[mysql@riyimei ~]$ 2021-02-21T02:32:44.036416Z mysqld_safe Logging to '/data/mysql/3306/logs/alert_3306.log'.2021-02-21T02:32:44.078430Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/3306/data[mysql@riyimei ~]$
查看数据库端口
[mysql@riyimei ~]$ netstat -lntup(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp6 0 0 :::3306 :::* LISTEN 19338/mysqldtcp6 0 0 :::22 :::* LISTEN -[mysql@riyimei ~]$
启动日志
2021-02-21T02:32:44.036416Z mysqld_safe Logging to '/data/mysql/3306/logs/alert_3306.log'.2021-02-21T02:32:44.078430Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/3306/data2021-02-21T02:32:44.332944Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2021-02-21T02:32:44.333041Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled2021-02-21T02:32:44.333062Z 0 [Note] /app/mysql/bin/mysqld (mysqld 5.7.33-log) starting as process 19338 ...2021-02-21T02:32:44.337205Z 0 [Note] InnoDB: PUNCH HOLE support available2021-02-21T02:32:44.337236Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2021-02-21T02:32:44.337241Z 0 [Note] InnoDB: Uses event mutexes2021-02-21T02:32:44.337243Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier2021-02-21T02:32:44.337245Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.112021-02-21T02:32:44.337249Z 0 [Note] InnoDB: Using Linux native AIO2021-02-21T02:32:44.337409Z 0 [Note] InnoDB: Number of pools: 12021-02-21T02:32:44.337496Z 0 [Note] InnoDB: Using CPU crc32 instructions2021-02-21T02:32:44.338323Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M2021-02-21T02:32:44.343291Z 0 [Note] InnoDB: Completed initialization of buffer pool2021-02-21T02:32:44.345147Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().2021-02-21T02:32:44.374764Z 0 [Note] InnoDB: Highest supported file format is Barracuda.2021-02-21T02:32:44.398600Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables2021-02-21T02:32:44.398665Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...2021-02-21T02:32:44.413876Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.2021-02-21T02:32:44.414516Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.2021-02-21T02:32:44.414544Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.2021-02-21T02:32:44.414799Z 0 [Note] InnoDB: Waiting for purge to start2021-02-21T02:32:44.468259Z 0 [Note] InnoDB: 5.7.33 started; log sequence number 27468322021-02-21T02:32:44.469474Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/3306/data/ib_buffer_pool2021-02-21T02:32:44.471023Z 0 [Note] Plugin 'FEDERATED' is disabled.2021-02-21T02:32:44.474944Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210221 10:32:442021-02-21T02:32:44.501475Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.2021-02-21T02:32:44.501630Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.2021-02-21T02:32:44.504096Z 0 [Warning] CA certificate ca.pem is self signed.2021-02-21T02:32:44.504277Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.2021-02-21T02:32:44.504662Z 0 [Note] Server hostname (bind-address): '*'; port: 33062021-02-21T02:32:44.504857Z 0 [Note] IPv6 is available.2021-02-21T02:32:44.504881Z 0 [Note] - '::' resolves to '::';2021-02-21T02:32:44.504918Z 0 [Note] Server socket created on IP: '::'.2021-02-21T02:32:44.512936Z 0 [Note] Failed to start slave threads for channel ''2021-02-21T02:32:44.521181Z 0 [Note] Event Scheduler: Loaded 0 events2021-02-21T02:32:44.521741Z 0 [Note] /app/mysql/bin/mysqld: ready for connections.Version: '5.7.33-log' socket: '/data/mysql/3306/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
登陆数据库 拷贝一份配置文件 并修改配置文件 临时登陆密码查看日志
[mysql@riyimei ~]$ cp /data/mysql/3306/my.cnf /home/mysql/.my.cnf[mysql@riyimei ~]$[mysql@riyimei ~]$ ls -la /home/mysql/total 24drwx------ 2 mysql mysql 114 Feb 21 10:35 .drwxr-xr-x. 7 root root 135 Feb 21 10:17 ..-rw------- 1 mysql mysql 679 Feb 21 10:32 .bash_history-rw-r--r-- 1 mysql mysql 18 Aug 8 2019 .bash_logout-rw-r--r-- 1 mysql mysql 214 Feb 21 10:21 .bash_profile-rw-r--r-- 1 mysql mysql 231 Aug 8 2019 .bashrc-rw-r----- 1 mysql mysql 937 Feb 21 10:35 .my.cnf-rw------- 1 mysql mysql 648 Feb 21 10:22 .viminfo[mysql@riyimei ~]$
[mysql@riyimei ~]$ mysql -uroot -hlocalhost -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.33-logCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> set password='123456';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)mysql>
停止数据库
[mysql@riyimei ~]$ mysqladmin -uroot shutdown -pEnter password:[mysql@riyimei ~]$ 2021-02-21T02:46:15.388746Z mysqld_safe mysqld from pid file /data/mysql/3306/tmp/mysql.pid ended[1]+ Done mysqld_safe --defaults-file=/data/mysql/3306/my.cnf[mysql@riyimei ~]$
2021-02-21T02:46:12.906897Z 0 [Note] Giving 0 client threads a chance to die gracefully2021-02-21T02:46:12.906926Z 0 [Note] Shutting down slave threads2021-02-21T02:46:12.906934Z 0 [Note] Forcefully disconnecting 0 remaining clients2021-02-21T02:46:12.906940Z 0 [Note] Event Scheduler: Purging the queue. 0 events2021-02-21T02:46:12.907045Z 0 [Note] Binlog end2021-02-21T02:46:12.908580Z 0 [Note] Shutting down plugin 'ngram'2021-02-21T02:46:12.908601Z 0 [Note] Shutting down plugin 'partition'2021-02-21T02:46:12.908605Z 0 [Note] Shutting down plugin 'BLACKHOLE'2021-02-21T02:46:12.908608Z 0 [Note] Shutting down plugin 'ARCHIVE'2021-02-21T02:46:12.908609Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'2021-02-21T02:46:12.908642Z 0 [Note] Shutting down plugin 'MRG_MYISAM'2021-02-21T02:46:12.908646Z 0 [Note] Shutting down plugin 'MyISAM'2021-02-21T02:46:12.908651Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'2021-02-21T02:46:12.908653Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'2021-02-21T02:46:12.908672Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'2021-02-21T02:46:12.908832Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'2021-02-21T02:46:12.908913Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'2021-02-21T02:46:12.908964Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'2021-02-21T02:46:12.909088Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'2021-02-21T02:46:12.909235Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'2021-02-21T02:46:12.909265Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'2021-02-21T02:46:12.909400Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'2021-02-21T02:46:12.909491Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'2021-02-21T02:46:12.909544Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'2021-02-21T02:46:12.909671Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'2021-02-21T02:46:12.909752Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'2021-02-21T02:46:12.909784Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'2021-02-21T02:46:12.909854Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'2021-02-21T02:46:12.909914Z 0 [Note] Shutting down plugin 'INNODB_METRICS'2021-02-21T02:46:12.909916Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'2021-02-21T02:46:12.909918Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'2021-02-21T02:46:12.909919Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'2021-02-21T02:46:12.909920Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'2021-02-21T02:46:12.909923Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'2021-02-21T02:46:12.909935Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'2021-02-21T02:46:12.909972Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'2021-02-21T02:46:12.909990Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'2021-02-21T02:46:12.910134Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'2021-02-21T02:46:12.910139Z 0 [Note] Shutting down plugin 'INNODB_CMP'2021-02-21T02:46:12.910140Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'2021-02-21T02:46:12.910142Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'2021-02-21T02:46:12.910143Z 0 [Note] Shutting down plugin 'INNODB_TRX'2021-02-21T02:46:12.910145Z 0 [Note] Shutting down plugin 'InnoDB'2021-02-21T02:46:12.910280Z 0 [Note] InnoDB: FTS optimize thread exiting.2021-02-21T02:46:12.910475Z 0 [Note] InnoDB: Starting shutdown...2021-02-21T02:46:13.010929Z 0 [Note] InnoDB: Dumping buffer pool(s) to /data/mysql/3306/data/ib_buffer_pool2021-02-21T02:46:13.011354Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 210221 10:46:132021-02-21T02:46:14.756073Z 0 [Note] InnoDB: Shutdown completed; log sequence number 27468602021-02-21T02:46:14.757577Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"2021-02-21T02:46:14.757603Z 0 [Note] Shutting down plugin 'MEMORY'2021-02-21T02:46:14.757608Z 0 [Note] Shutting down plugin 'CSV'2021-02-21T02:46:14.757630Z 0 [Note] Shutting down plugin 'sha256_password'2021-02-21T02:46:14.757634Z 0 [Note] Shutting down plugin 'mysql_native_password'2021-02-21T02:46:14.757727Z 0 [Note] Shutting down plugin 'binlog'2021-02-21T02:46:14.758076Z 0 [Note] /app/mysql/bin/mysqld: Shutdown complete2021-02-21T02:46:15.388746Z mysqld_safe mysqld from pid file /data/mysql/3306/tmp/mysql.pid ended
设置启动脚本
拷贝
[mysql@riyimei ~]$ cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
# Set some defaultsmysqld_pid_file_path=/data/mysql/3306/tmp/mysql.pidif test -z "$basedir"thenbasedir=/app/mysqlbindir=/app/mysql/binif test -z "$datadir"thendatadir=/data/mysql/datafisbindir=/app/mysql/binlibexecdir=/app/mysql/bin
[mysql@riyimei ~]$ /etc/init.d/mysqld startStarting MySQL. SUCCESS![mysql@riyimei ~]$ /etc/init.d/mysqld stopShutting down MySQL.. SUCCESS![mysql@riyimei ~]$ netstat -lntup(No info could be read for "-p": geteuid()=401 but you should be root.)Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp6 0 0 :::22 :::* LISTEN -[mysql@riyimei ~]$
开启远程登陆
改表#登录数据库:mysql -u root -pmysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>FLUSH PRIVILEGES;

