mysql 5.7在初始化数据库中遇到的问题

mysqld_install_db已经deprecated

[mysql@rws1270149 bin]$ ./mysql_install_db --datadir=/scratch/mysql5.7/data --basedir=/scratch/mysql5.7
2019-06-17 23:01:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

mysql5.7是使用 mysqld --initialize来初始化数据库

[mysql@rws1270149 bin]$ ./mysqld --initialize --datadir=/scratch/mysql5.7/data --basedir=/scratch/mysql5.7
<=====上面在初始化数据库的时候没有任何输出,也没有任何报错,其实是有问题的

初始化数据库后,在启动数据库的时候会报错
[mysql@rws1270149 bin]$ ./mysqld_safe --defaults-file=/scratch/my57.cnf
2019-06-18T07:00:27.475385Z mysqld_safe Logging to '/scratch/mysql5.7/data/mysqld.log'.
2019-06-18T07:00:27.506163Z mysqld_safe Starting mysqld daemon with databases from /scratch/mysql5.7/data
2019-06-18T07:00:29.432064Z mysqld_safe mysqld from pid file /scratch/mysql5.7/data/rws1270149.us.oracle.com.pid ended
查看mysqld.log文件可以看到如下的错误

2019-06-18T07:00:27.793936Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2019-06-18T07:00:27.794417Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-18T07:00:27.794501Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-06-18T07:00:27.794518Z 0 [Note] Server hostname (bind-address): '*'; port: 4444
2019-06-18T07:00:27.794598Z 0 [Note] IPv6 is available.
2019-06-18T07:00:27.794616Z 0 [Note]   - '::' resolves to '::';
2019-06-18T07:00:27.794656Z 0 [Note] Server socket created on IP: '::'.
2019-06-18T07:00:27.795535Z 0 [Warning] Insecure configuration for --pid-file: Location '/scratch' in the path is accessible to all OS users. Consider choosing a different directory.
2019-06-18T07:00:27.795669Z 0 [Warning] Failed to open optimizer cost constant tables

2019-06-18T07:00:27.795845Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2019-06-18T07:00:27.795874Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2019-06-18T07:00:27.795944Z 0 [ERROR] Aborting

通过以下的命令可以将mysql启动起来

[mysql@rws1270149 bin]$ ./mysqld_safe --defaults-file=/scratch/my57.cnf --skip-grant-tables
2019-06-18T07:04:13.008667Z mysqld_safe Logging to '/scratch/mysql5.7/data/mysqld.log'.
2019-06-18T07:04:13.039981Z mysqld_safe Starting mysqld daemon with databases from /scratch/mysql5.7/data

但是仍然能够在mysqld.log中发现好多错误

2019-06-18T07:04:13.334422Z 0 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_instance' has the wrong structure
2019-06-18T07:04:13.334457Z 0 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_thread_by_event_name' has the wrong structure
2019-06-18T07:04:13.334491Z 0 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_user_by_event_name' has the wrong structure
2019-06-18T07:04:13.334544Z 0 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_account_by_event_name' has the wrong structure
2019-06-18T07:04:13.334584Z 0 [ERROR] Native table 'performance_schema'.'events_waits_summary_global_by_event_name' has the wrong structure
2019-06-18T07:04:13.334619Z 0 [ERROR] Native table 'performance_schema'.'file_instances' has the wrong structure
2019-06-18T07:04:13.334652Z 0 [ERROR] Native table 'performance_schema'.'file_summary_by_event_name' has the wrong structure
2019-06-18T07:04:13.334685Z 0 [ERROR] Native table 'performance_schema'.'file_summary_by_instance' has the wrong structure
2019-06-18T07:04:13.334718Z 0 [ERROR] Native table 'performance_schema'.'host_cache' has the wrong structure
2019-06-18T07:04:13.334751Z 0 [ERROR] Native table 'performance_schema'.'mutex_instances' has the wrong structure
2019-06-18T07:04:13.334784Z 0 [ERROR] Native table 'performance_schema'.'objects_summary_global_by_type' has the wrong structure
2019-06-18T07:04:13.334817Z 0 [ERROR] Native table 'performance_schema'.'performance_timers' has the wrong structure
2019-06-18T07:04:13.334849Z 0 [ERROR] Native table 'performance_schema'.'rwlock_instances' has the wrong structure

最后发现其实是通过mysqld --initialize创建的数据库有问题,mysql、performance_schema、information_schema、sys这几个数据库其实根本就没创建出来

这个问题的根本原因是因为存在/etc/my.cnf这个文件,这个文件中存在group [mysqld] 而mysqld --initialize会去读这个配置里面的这个组。所以会导致创建的数据库有问题


你可能感兴趣的:(mysql)