
mysql安装
mysql的使用
一些修改密码的骚 *** 作:
不小心修改了
sudo cat /etc/mysql/debian.cnf
导致只能skip密码来修改密码
启动mysql数据库
sudo /etc/init.d/mysql start
重启
sudo /etc/init.d/mysql restart
关闭
sudo /etc/init.d/mysql stop
1.修改数据库配置文件绕过密码登录
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
找到[mysqld]
添加如下内容:
skip-grant-tables
2.重启数据库
sudo /etc/init.d/mysql restart
3.登录
mysql -u root -p
密码随便
4.修改root用户密码
MySql 从8.0开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空
因此,如果不为空,先置空字段在修改密码
use mysql;
update user set authentication_string='' where user='root'; --将字段置为空
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
--修改密码为123456
如果为空,则直接修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
--修改密码为123456
其中如果出现问题:
flush privileges
然后继续修改,解决
然后再把配置文件中那个
skip-grant-tables
不然后续登录还是直接跳过密码
over!
vscode中配置mysql环境
includepath中有mysql
#include
#include
#include
using namespace std;
// g++ mysqltest.cpp `mysql_config --cflags --libs` -o mysqltest
int main(int argc, char *argv[])
{
MYSQL conn;
int res;
mysql_init(&conn);
//"root":数据库管理员 "123":root密码 "test":数据库的名字
if (mysql_real_connect(&conn, "localhost", "root", "your_password", "your_database", 0, NULL, CLIENT_FOUND_ROWS))
{
cout << "connect success" << endl;
res = mysql_query(&conn, "insert into your_table values(1,'firstuser')");
if (res)
{
printf("error\n");
}
else
{
printf("OK\n");
}
mysql_close(&conn);
}
else
{
cout << "connect failed" << endl;
}
return 0;
}
编译(注意反单引号):
g++ sqltest.cpp `mysql_config --cflags --libs` -o sqltest
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)