6.27 tinywebserver项目运行MySql ERROR报错问题

参考文章:

1.MySQL登录报错 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
https://blog.csdn.net/m0_64304713/article/details/133975710
2.初试TinyWebServer所遇到的问题
https://blog.csdn.net/MYMarcoreus/article/details/121961504
3.ubuntu安裝mysql后配置/etc/my.cnf配置文件沒生效,解决办法https://blog.csdn.net/chensheng8085497/article/details/105449329

问题:./server运行不起来
/home/abc/project/TinyWebServer-master 目录下日志文件,查看日志命令
cat 2024_06_27_ServerLog

2024-06-27 20:54:27.466947 [erro]: MySQL Error
2024-06-27 21:07:19.101082 [erro]: MySQL Error
2024-06-27 21:09:08.751254 [erro]: MySQL Error
2024-06-27 21:16:43.171057 [erro]: MySQL Error
2024-06-27 21:22:53.076595 [erro]: MySQL Error
2024-06-27 21:25:02.870739 [erro]: MySQL Error
2024-06-27 21:29:56.847410 [erro]: MySQL Error
2024-06-27 21:32:18.786917 [erro]: MySQL Error
2024-06-27 21:34:28.824250 [erro]: MySQL Error
2024-06-27 21:42:53.898647 [erro]: MySQL Error
2024-06-27 21:53:03.129176 [erro]: MySQL Error

解决办法:
1.通过修改CGImysql文件夹下的sql_connection_pool.cpp文件connection_pool::init()函数,

void connection_pool::init(string url, string User, string PassWord, string DBName, int Port, int MaxConn, int close_log)
{
	m_url = url;
	m_Port = Port;
	m_User = User;
	m_PassWord = PassWord;
	m_DatabaseName = DBName;
	m_close_log = close_log;

	for (int i = 0; i < MaxConn; i++)
	{
		MYSQL* con = NULL;
		MYSQL* ret = NULL;

		ret = mysql_init(con);
		if (ret == NULL)
		{
          // 如果mysql_init()返回空,那就打印该信息
			LOG_ERROR("MySQL Error: mysql_init() returns NULL");
			exit(1);
		} else {
			con = ret;
		}

		ret = mysql_real_connect(con, url.c_str(), User.c_str(), PassWord.c_str(), DBName.c_str(), Port, NULL, 0);
		if (ret == NULL)
		{
          // 如果mysql_real_connect()返回空,那就使用mysql_errorh和mysql_errno打印具体的出错信息
			string err_info( mysql_error(con) );
			err_info = (string("MySQL Error[errno=")
				+ std::to_string(mysql_errno(con)) + string("]: ") + err_info);
			LOG_ERROR( err_info.c_str() );
			exit(1);
		} else {
			con = ret;
		}

		connList.push_back(con);
		++m_FreeConn;
	}

	reserve = sem(m_FreeConn);
	m_MaxConn = m_FreeConn;
}

修改后可以看到日志报错具体信息

2024-06-27 21:54:20.490795 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 21:59:55.566847 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 22:06:41.300968 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 22:10:06.623197 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 22:13:09.937179 [erro]: MySQL Error
2024-06-27 23:20:37.107284 [erro]: MySQL Error[errno=0]: 
2024-06-27 23:31:32.943467 [erro]: MySQL Error[errno=0]: 
2024-06-27 23:35:20.669176 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 23:44:51.896570 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)
2024-06-27 23:49:16.653133 [erro]: MySQL Error[errno=1045]: Access denied for user 'duo'@'localhost' (using password: YES)

大概意思时没有权限,看配置文件my.cnf内容,查看配置文件路径命令为, 为命令一部分 ‘ 为命令一部分 ` 为命令一部分(which mysqld) --verbose --help |grep -A 1 ‘Default options’![image.png](https://img-blog.csdnimg.cn/img_convert/4a89d1d2f88b865d76fd08ad01d54a23.png) 到这里问题依然没解决,日志报错内容一样 2. 查看另外一个mysql配置文件cat /etc/apparmor.d/usr.sbin.mysqld ![image.png](https://img-blog.csdnimg.cn/img_convert/56fd9263a363fe6f906122e09debf8c8.png) **添加这条命令,保存,由于是只读文件,输入 **w !sudo tee %`** 回车,这里已经保存成功了,再次输入q!强制退出即可**
image.png
3.reboot,重启后,重新make server ,./server ,运行成功,
image.png
4.浏览器输入127.0.0.1:9006成功启动~
image.png

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值