dongzhuner6981 2017-03-04 09:58
浏览 157

登录到mysql时权限被拒绝,但能够从cmd digitalocean登录

I have created a droplet with digitalocean and installed mariadb using the apt install mariadb-server command. Now I want to connect to my server using php and I use this:

mysqli_connect('localhost', 'root', '');

The problem is I always have Access denied for user 'root'@'localhost' error. I don't understand why this happens. I can login using mysql -uroot when I am logged into my server. Also when I create a new user using

CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
GRANT ALL ON *.* TO 'test'@'localhost';

I can connect using php mysqli_connect. What am I doing wrong? Why can't I connect with root?

  • 写回答

2条回答 默认 最新

  • duanhongxian6982 2017-03-04 10:07
    关注

    To connect this with server you need to create a database user first, and after creating user associate it with your database then the error will go away. hope this work for you. :) Goto MySQL Database > Create new user > Add the user with the database you want to use Like this: Check this for have a look how it looks like > Then simply use this mysqli_connect("host", "your_created_user", "your_user_password", "DB_name");

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大