1.安装sysbench
(1)yum安装
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
(2)源码安装
wget https://github.com/akopytov/sysbench/archive/0.5.zip
直接下载包,对其进行解压
cd sysbench-0.5
./autogen.sh
./configure
make -j
make install
到此为止安装成功
2,测试sysbench是否安装成功
sysbench --help
如上图所示,则表示完成。
3.连接数据库
sysbench --test=/usr/share/sysbench/oltp_insert.lua --mysql-host=172.16.227.133 --mysql-port=10001 --mysql-user=root --mysql-password='123456' --mysql-db=testdb --db-driver=mysql --tables=10 --table-size=500000 --report-interval=10 --threads=12 prepare
如国执行命令后出现以下错误1:
FATAL: unable to connect to MySQL server on host '172.16.227.133', port 10001, aborting...
FATAL: error 1049: Unknown database 'testdb'
说明是没有提前创建数据库,需要创建好才可以用,
出现以下错误2,如下:
FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
FATAL: unable to connect to MySQL server on host '172.16.227.133', port 10001, 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 directory
这个错误是用的mysql 8.0版本,mysql8.0用的密码是sha2,而mysql5.7密码是native,需要把mysql8.0密码换成native模式,则需要操作如下:
mysql> alter user root@'%' identified by '123456' password expire never;
Query OK, 0 rows affected (0.01 sec)
mysql> alter user root@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
以上是常见的错误,也是本人遇到的坑,大家遇到什么错误了可以私信或者评论,希望会大家有所帮助