640?wx_fmt=jpeg

Linux 下安装了 MySQL 初始化后,进行启动时,遇到两个错误,特地记录下来。分享给大家。具体报错如图:


 
 

[root@k8s-master-02 support-files]# su - mysql
Last login: Fri Aug 16 05:39:30 EDT 2019 on pts/0
[mysql@k8s-master-02 ~]$ service mysql start
/etc/init.d/mysql: line 239: my_print_defaults: command not found
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)


其实报错的这两个错误是两个脚本。在脚本中找不到默认路径或者找不到默认的脚本。第一个问题是需要将my_print_defaults拷贝到usr/bin下。然后再次启动发现第一个错误不见了,接下来处理第二个错误。


 
 

[root@k8s-master-02 bin]# cp my_print_defaults /usr/bin
[root@k8s-master-02 bin]# su - mysql
Last login: Fri Aug 16 05:46:55 EDT 2019 on pts/0
[mysql@k8s-master-02 ~]$ service mysql start
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)


第二个问题是配置文件重复的问题,需要先将/etc/my.cnf重新mv成别的名字或者删掉。将手动创建的做个软连到/etc/my.cnf。检查用了哪个配置文件:mysqld --print-defaults,然后就会打印出来配置文件的信息,查看是不是我们自己配置的配置文件。


 
 

[mysql@k8s-master-02 ~]$ mysqld --print-defaults
mysqld would have been started with the following arguments:
--user=mysql --port=3306 --basedir=/opt/mysql --datadir=/opt/data --socket=/opt/data/mysqld.sock --pid-file=mysql.pid --character-set-server=utf8 --skip_name_resolve=1 --lower_case_table_names=1 --max_connections=1000 --max_connect_errors=1000000 --table_open_cache=4000 --table_definition_cache=4000 --table_open_cache_instances=64 --max_allowed_packet=32M --sort_buffer_size=16M --join_buffer_size=16M --thread_cache_size=450 --query_cache_size=0 --query_cache_type=0 --interactive_timeout=600 --wait_timeout=600 --tmp_table_size=96M --max_heap_table_size=96M --general_log=1 --general_log_file=general.log --slow_query_log=1 --slow_query_log_file=/opt/log/slow.log --log_error=/opt/log/error.log --long_query_time=1 --server-id=170 --log_bin=mysql-bin --log_slave_updates=on --sync_binlog=1 --binlog_cache_size=4M --max_binlog_cache_size=2G --max_binlog_size=1G --expire_logs_days=7 --master_info_repository=TABLE --relay_log_info_repository=TABLE --binlog_format=row --key_buffer_size=32M --read_buffer_size=8M --read_rnd_buffer_size=16M --lock_wait_timeout=3600 --innodb_thread_concurrency=0 --transaction_isolation=REPEATABLE-READ --innodb_buffer_pool_size=2G --innodb_buffer_pool_instances=8 --innodb_flush_log_at_trx_commit=1 --innodb_log_buffer_size=32M --innodb_log_file_size=2G --innodb_log_files_in_group=3
[mysql@k8s-master-02 ~]$


默认会用到/etc/my.cnf,所有将默认的重命名或者删掉,然后用我们自己定义的配置文件做个软连接到/etc下即可。

 
 

[root@k8s-master-02 conf]# ln -s /opt/mysql/conf/my.cnf /etc/my.cnf
[root@k8s-master-02 conf]#
[root@k8s-master-02 conf]#
[root@k8s-master-02 conf]# su - mysql
Last login: Fri Aug 16 05:53:09 EDT 2019 on pts/0
[mysql@k8s-master-02 ~]$ service mysql start
Starting MySQL..... SUCCESS!


启动成功之后,进行登录数据库然后修改密码,并创建用户:


 
 

mysql -u root -p之后输入密码:
mysql> select Host,User from mysql.user;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.01 sec)

mysql> create user tigergao;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user "tigergao"@"%" identified by "tigergao@123";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select Host,User from mysql.user;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| % | tigergao |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)


接下来进行 mysql 的插件升级,具体步骤如下:


 
 

[mysql@k8s-master-02 data]$ mysql_upgrade -u root -p
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.1).
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.


Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐