四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

时间:2022-03-12 21:08:04

1.在Linux中创建用户mysql和主目录,并创建密码

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

2.解压缩tar.gz并拷贝到/usr/local/mysql目录下面

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

3.把/usr/local/mysql文件夹拥有者改为mysql

   进入到/usr/local/mysql目录下面后,由于我没有创建mysql用户组,故命令如下

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

4.安装

   由于5.7版本的安装已经不建议使用mysql_install_db 来安装,而是使用mysqld,

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

   出现了错误“error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory”

   很明显缺少了库文件,使用yum安装:yum install libaio*

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

   再次运行mysqld,以完成安装

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

   为遵守Linux管理规范,修改/usr/local/mysql属主为root,/home/mysql/mysqldata为mysql用户 

   四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装) 

5.配置mysql开机启动

  1)把配置文件考到/etc/init.d/mysql文件

     四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

     并编辑该文件中的basedir和datadir两个文件以指定目录,后增加启动

    四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

 

  2)新建mysql的日志文件

     在/home/mysql/log下新建mysqld.log作为日志文件

  3)配置my.cnf

     这个文件在mysql安装路径下的support-files目录my-default.cnf文件,Centos7也有默认有该文件,在/etc/my.cnf,笔者选择直接修改/etc/my.cnf文件如下,

[client]
default-character-set=utf8

[mysqld]
character-set-server=utf8
datadir=/home/mysql/mysqldata
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
# symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/home/mysql/log/mysqld.log
pid-file=/home/mysql/pid/mariadb.pid
#
# include all files from the config directory
#
# !includedir /etc/my.cnf.d

6.启动mysql 

    四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装) 

   根据错误提示,我明明已经指定了pid文件为/home/mysql/pid/mariadb.pid,不应该是这样,检查一下

 查看日志如下:

    

2016-11-02T09:15:46.208020Z mysqld_safe Starting mysqld daemon with databases from /home/mysql/mysqldata
2016-11-02T09:15:46.394034Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-02T09:15:46.394169Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2016-11-02T09:15:46.394208Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.16) starting as process 2237 ...
2016-11-02T09:15:46.399508Z 0 [Note] InnoDB: PUNCH HOLE support not available
2016-11-02T09:15:46.399542Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-11-02T09:15:46.399551Z 0 [Note] InnoDB: Uses event mutexes
2016-11-02T09:15:46.399558Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2016-11-02T09:15:46.399565Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-11-02T09:15:46.399572Z 0 [Note] InnoDB: Using Linux native AIO
2016-11-02T09:15:46.399838Z 0 [Note] InnoDB: Number of pools: 1
2016-11-02T09:15:46.399961Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-11-02T09:15:46.401685Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-11-02T09:15:46.410865Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-11-02T09:15:46.413085Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2016-11-02T09:15:46.424959Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-11-02T09:15:46.438198Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-11-02T09:15:46.438338Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-11-02T09:15:46.724321Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-11-02T09:15:46.725425Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-11-02T09:15:46.725513Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-11-02T09:15:46.726427Z 0 [Note] InnoDB: Waiting for purge to start
2016-11-02T09:15:46.776629Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 1210151
2016-11-02T09:15:46.777641Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2016-11-02T09:15:46.778033Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2016-11-02T09:15:46.778773Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-11-02T09:15:46.778909Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-11-02T09:15:46.779208Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-11-02T09:15:46.779325Z 0 [Note] IPv6 is available.
2016-11-02T09:15:46.779389Z 0 [Note] - '::' resolves to '::';
2016-11-02T09:15:46.779459Z 0 [Note] Server socket created on IP: '::'.
2016-11-02T09:15:46.779766Z 0 [Note] InnoDB: Loading buffer pool(s) from /home/mysql/mysqldata/ib_buffer_pool
2016-11-02T09:15:46.780067Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161102 17:15:46
2016-11-02T09:15:46.787064Z 0 [Warning] Failed to open optimizer cost constant tables

2016-11-02T09:15:46.787297Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2016-11-02T09:15:46.787408Z 0 [ERROR] Aborting

2016-11-02T09:15:46.787460Z 0 [Note] Binlog end
2016-11-02T09:15:46.787548Z 0 [Note] Shutting down plugin 'ngram'
2016-11-02T09:15:46.787594Z 0 [Note] Shutting down plugin 'ARCHIVE'
2016-11-02T09:15:46.787633Z 0 [Note] Shutting down plugin 'partition'
2016-11-02T09:15:46.787669Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2016-11-02T09:15:46.787707Z 0 [Note] Shutting down plugin 'CSV'
2016-11-02T09:15:46.787747Z 0 [Note] Shutting down plugin 'MEMORY'
2016-11-02T09:15:46.787787Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2016-11-02T09:15:46.787827Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2016-11-02T09:15:46.787865Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2016-11-02T09:15:46.787902Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2016-11-02T09:15:46.787937Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2016-11-02T09:15:46.787973Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2016-11-02T09:15:46.788009Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2016-11-02T09:15:46.788044Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2016-11-02T09:15:46.788079Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2016-11-02T09:15:46.788115Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2016-11-02T09:15:46.788192Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2016-11-02T09:15:46.788231Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2016-11-02T09:15:46.788267Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2016-11-02T09:15:46.788303Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2016-11-02T09:15:46.788338Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2016-11-02T09:15:46.788374Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2016-11-02T09:15:46.788409Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2016-11-02T09:15:46.788444Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2016-11-02T09:15:46.788480Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2016-11-02T09:15:46.788516Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2016-11-02T09:15:46.788552Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2016-11-02T09:15:46.788596Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2016-11-02T09:15:46.788634Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2016-11-02T09:15:46.788670Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2016-11-02T09:15:46.788705Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2016-11-02T09:15:46.788745Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2016-11-02T09:15:46.788780Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2016-11-02T09:15:46.788815Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2016-11-02T09:15:46.788849Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2016-11-02T09:15:46.788884Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-11-02T09:15:46.788918Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2016-11-02T09:15:46.788952Z 0 [Note] Shutting down plugin 'InnoDB'
2016-11-02T09:15:46.789030Z 0 [Note] InnoDB: FTS optimize thread exiting.
2016-11-02T09:15:46.789359Z 0 [Note] InnoDB: Starting shutdown...
2016-11-02T09:15:46.889989Z 0 [Note] InnoDB: Dumping buffer pool(s) to /home/mysql/mysqldata/ib_buffer_pool
2016-11-02T09:15:46.890414Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 161102 17:15:46
2016-11-02T09:15:48.601418Z 0 [Note] InnoDB: Shutdown completed; log sequence number 1210170
2016-11-02T09:15:48.603024Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2016-11-02T09:15:48.603095Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-11-02T09:15:48.603260Z 0 [Note] Shutting down plugin 'MyISAM'
2016-11-02T09:15:48.603328Z 0 [Note] Shutting down plugin 'sha256_password'
2016-11-02T09:15:48.603384Z 0 [Note] Shutting down plugin 'mysql_native_password'
2016-11-02T09:15:48.603585Z 0 [Note] Shutting down plugin 'binlog'
2016-11-02T09:15:48.603850Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

2016-11-02T09:15:48.679796Z mysqld_safe mysqld from pid file /home/mysql/mysqldata/iZ25ufmpy4sZ.pid ended

    可以看出来,是因为缺少了mysql这个schema下的plugin表,网上也看到了很多的解决办法,但是都没有解决我的问题,我的解决办法是

    先运行,通过这个命令可以看到/home/mysql/mysqldata下已经生成了mysql这个schema

 ./mysql_install_db  --user=mysql 

    再次运行

   

[root@Z bin]#  ./mysqld --user=mysql 
2016-11-02T15:02:53.243624Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-02T15:02:53.243765Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2016-11-02T15:02:53.243807Z 0 [Note] ./mysqld (mysqld 5.7.15) starting as process 1943 ...
2016-11-02T15:02:53.249811Z 0 [Note] InnoDB: PUNCH HOLE support not available
2016-11-02T15:02:53.249839Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-11-02T15:02:53.249846Z 0 [Note] InnoDB: Uses event mutexes
2016-11-02T15:02:53.249853Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2016-11-02T15:02:53.249858Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-11-02T15:02:53.249863Z 0 [Note] InnoDB: Using Linux native AIO
2016-11-02T15:02:53.250168Z 0 [Note] InnoDB: Number of pools: 1
2016-11-02T15:02:53.250300Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-11-02T15:02:53.252147Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-11-02T15:02:53.262112Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-11-02T15:02:53.264522Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2016-11-02T15:02:53.276640Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-11-02T15:02:53.278080Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 2528562
2016-11-02T15:02:53.278181Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 2528571
2016-11-02T15:02:53.278407Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 2528571
2016-11-02T15:02:53.278465Z 0 [Note] InnoDB: Database was not shutdown normally!
2016-11-02T15:02:53.278513Z 0 [Note] InnoDB: Starting crash recovery.
2016-11-02T15:02:53.394792Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2016-11-02T15:02:53.394951Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-11-02T15:02:53.395090Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-11-02T15:02:53.727605Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-11-02T15:02:53.728927Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-11-02T15:02:53.729050Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-11-02T15:02:53.729556Z 0 [Note] InnoDB: Waiting for purge to start
2016-11-02T15:02:53.779820Z 0 [Note] InnoDB: 5.7.15 started; log sequence number 2528571
2016-11-02T15:02:53.780219Z 0 [Note] Plugin 'FEDERATED' is disabled.
2016-11-02T15:02:53.784515Z 0 [Note] InnoDB: Loading buffer pool(s) from /home/mysql/mysqldata/ib_buffer_pool
2016-11-02T15:02:53.787135Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161102 23:02:53
2016-11-02T15:02:53.787241Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2016-11-02T15:02:53.787349Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL_CTX_set_default_verify_paths failed
2016-11-02T15:02:53.787643Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-11-02T15:02:53.787763Z 0 [Note] IPv6 is available.
2016-11-02T15:02:53.787820Z 0 [Note] - '::' resolves to '::';
2016-11-02T15:02:53.787880Z 0 [Note] Server socket created on IP: '::'.
2016-11-02T15:02:53.803340Z 0 [Note] Event Scheduler: Loaded 0 events
2016-11-02T15:02:53.803582Z 0 [Note] ./mysqld: ready for connections.
Version: '5.7.15' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)

  问题解决了,服务已经正常启动了。

    四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)

 

7.链接

    四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)