赞
踩
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt autoclean
sudo apt-get update
sudo apt-get install mysql-server
sudo cat /etc/mysql/debian.cnf // 查看配置文件
//用里面的user和password登录
mysql -u debian-sys-maint -p // 登录默认账号
use mysql
update user set authentication_string=‘’ where user=‘root’; //将字段置为空
alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘123456’; //修改密码
exit
https://zhuanlan.zhihu.com/p/587097435#:~:text=MySQL8.0%E8%AE%BE%E7%BD%AE%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%201%201.%E7%99%BB%E5%BD%95MySQL%20mysql%20-u%20root%20-p%20%E8%BE%93%E5%85%A5%E6%82%A8%E7%9A%84%E5%AF%86%E7%A0%81,…%207%207.%E8%AE%BF%E9%97%AE%E6%95%B0%E6%8D%AE%E5%BA%93%20…%208%208.%E4%BF%AE%E6%94%B9%E5%8A%A0%E5%AF%86%E8%A7%84%E5%88%99%20…%20%E6%9B%B4%E5%A4%9A%E9%A1%B9%E7%9B%AE
上面的文章到第五步就行
接着:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 修改里面的配置文件,找到bind-address那一行注释掉
sudo service mysql restart
sudo ufw status
sudo ufw enable
sudo ufw disable
sudo ufw allow 9200 允许外部访问9200端口(tcp/udp)
sudo ufw allow 3690 允许外部访问3690端口(svn)
sudo ufw allow from 192.168.25.125 允许此IP访问所有的本机端口
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 22 允许指定的IP段访问特定端口
sudo ufw delete allow smtp 删除上面建立的某条规则,比如删除svn端口就是 sudo ufw delete allow 3690
安装依赖:sudo apt install mysql-server mysql-client libmysqlclient-dev
/* test.cpp */
#include <mysql.h>
#include <iostream>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
const char *server = "localhost";
const char *user = "root";
const char *password = ""; /* 此处改成你的密码 */
const char *database = "mysql"; /* 数据库名字,比如mysql*/
conn = mysql_init(NULL);
/* 连接数据库 */
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
cout << mysql_error(conn);
return -1;
}
/* 查询语句 */
if (mysql_query(conn, "show tables")) {
cout << mysql_error(conn));
return -2;
}
res = mysql_use_result(conn);
/* 打印查询结果 */
while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]);
/* 断开连接 */
mysql_free_result(res);
mysql_close(conn);
}
编译:g++ test.cpp -o test.app -I /usr/include/mysql -L/usr/lib/mysql -lmysqlclient
tips:如果在vscode中出现#include <mysql.h>这个文件找不到的情况,参考博客:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。