前言:
眼前小伙伴们对“lua连接mysql数据库”大体比较讲究,姐妹们都需要了解一些“lua连接mysql数据库”的相关文章。那么小编同时在网络上搜集了一些对于“lua连接mysql数据库””的相关知识,希望兄弟们能喜欢,我们快快来学习一下吧!Mysql8出来有一段时间了,有很多新特性非常吸引人,于是就安装好mysql-8.0.21数据库尝尝鲜。数据库是用二级制方式安装的,安装过程不复杂,如果想了解二进制安装详细过程,可以在文章下方留言,我会更新一篇文章,详细介绍安装过程和mysql8的参数。
mysql-8.0.21数据库安装好之后,就试着用sysbench建张10W记录的表,测试一下降序索引特性。
首先在数据库中创建了用于压测的数据库和用户
create database sbtest;CREATE USER 'tony'@'%' IDENTIFIED BY 'tony';GRANT ALL ON *.* TO 'tony'@'%';flush privileges;
数据库和用户都创建好之后,就用sysbench插入测试数据
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-socket=/data/mysql/mysql8/run/3308/mysql.sock --mysql-user=tony --mysql-password='tony' --mysql-db=sbtest --oltp-test-mode=complex --oltp-tables-count=1 --oltp-table-size=100000 --threads=128 --oltp-nontrx-mode=select --oltp-read-only=off --max-time=120 --report-interval=5 prepareFATAL: unable to connect to MySQL server on socket '/data/mysql/mysql8/run/3308/mysql.sock', aborting...FATAL: error 2059: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directoryFATAL: `prepare' function failed: /usr/share/sysbench/tests/include/oltp_legacy/common.lua:111: Failed to connect to the database
可是报错了,FATAL: error 2059: Authentication plugin 'caching_sha2_password' cannot be loaded:,认证组件“caching_sha2_password”没有被加载,查了一下资料,原来在mysql8以后,用户连接默认认证组件改为“caching_sha2_password”,而mysql5.7以前,默认的用户认证组件为“mysql_native_password”。
既然知道了原因,就临时将tony用户的认证组件修改“mysql_native_password”,然后运行sysbench插入数据
ALTER USER tony IDENTIFIED WITH mysql_native_password;flush privileges;[mysql@mysql ~]$ sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-socket=/data/mysql/mysql8/run/3308/mysql.sock --mysql-user=tony --mysql-password='tony' --mysql-db=sbtest --oltp-test-mode=complex --oltp-tables-count=1 --oltp-table-size=100000 --threads=128 --oltp-nontrx-mode=select --oltp-read-only=off --max-time=120 --report-interval=5 prepareWARNING: --max-time is deprecated, use --time insteadsysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)FATAL: unable to connect to MySQL server on socket '/data/mysql/mysql8/run/3308/mysql.sock', aborting...FATAL: error 1045: Access denied for user 'tony'@'localhost' (using password: YES)FATAL: `prepare' function failed: /usr/share/sysbench/tests/include/oltp_legacy/common.lua:111: Failed to connect to the database
竟然还报错,这次是连接不上库,为什么呢,检查用户是否正常
[root@localhost] 16:54:13 [performance_schema]>select user,host,plugin from mysql.user where user='tony';+------+------+-----------------------+| user | host | plugin |+------+------+-----------------------+| tony | % | mysql_native_password |+------+------+-----------------------+1 row in set (0.00 sec)
tony用户的host是不限制IP段了,plugin也修改成mysql_native_password,难道是密码不对
[root@localhost] 16:56:08 [performance_schema]>select user,host,plugin,authentication_string from mysql.user where user='tony';+------+------+-----------------------+-----------------------+| user | host | plugin | authentication_string |+------+------+-----------------------+-----------------------+| tony | % | mysql_native_password | |+------+------+-----------------------+-----------------------+1 row in set (0.71 sec)
看到这里,有没有想说点什么,密码竟然变成空了,原来执行修改认证组件命令时,也将密码置空了。
ALTER USER tony IDENTIFIED WITH mysql_native_password;
问题原因找到了,大家在生产操作时一定要注意,正确修改认证组件命令如下所示
alter user 'tony'@'%' identified with mysql_native_password by 'tony';flush privileges;
搞不好,就会出现大片应用连接不上数据库的尴尬事情了。
标签: #lua连接mysql数据库