Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 03-15-2017, 10:08 PM   #1
Registered: Jun 2014
Posts: 32

Rep: Reputation: Disabled
mysqli connect fails on debian, works on centOS

I'm trying to move a few websites from a centOS VD server to a new debian VD server.

I'm having trouble with codes that worked there for years but now refuse to work here on debian.

Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.86-1 x86_64 GNU/Linux

mysql Ver 14.14 Distrib 5.5.54, for debian-linux-gnu (x86_64) using readline 6.2

PHP 5.4.45-0+deb7u7 (cli) (built: Feb 7 2017 15:05:15)

I tried creating a new not-root user and granting all privileges while in --skip-grant-tables mode but no cigar.

Logged in ssh
created my database. Can log in from bash command line with:
mysql -uroot -p'MyPassword' Mydbname
all my data is there as it should be.

Connecting via php is failing with:
mysqli::mysqli(): (HY000/1045): Access denied for user 'root'@'localhost'

Have tried a pdo connection which fails with the same error

I've stripped this code down to a bare bones.

mysql is running on the default port

//$sys_dbhost='my VD Server IP address';

/etc/mysql/my.cnf has "port = 3306"

function db_connect()
global $dbh, $sys_dbname, $sys_dbhost,$sys_dbuser,$sys_dbpasswd;

$dbh = new mysqli($sys_dbhost, $sys_dbuser, $sys_dbpasswd);

if ($dbh->connect_error) {
die("Connection failed: " . $dbh->connect_error);


return $dbh;

Hmm. I see this is a FAQ all over the internet. Connecting to mysql hasn't always been this tricky.

Last edited by pittendrigh; 03-16-2017 at 08:16 AM.
Old 03-15-2017, 10:36 PM   #2
Registered: Jun 2014
Posts: 32

Original Poster
Rep: Reputation: Disabled
Ouch. After logging in from a bash command line several times I stopped and restarted
mysql with sudo /etc/init.d/mysql restart

Now i suddenly cannot log in (to mysql) even from bash
mysql -u root -p"Mypassword' Mydbname now fails with:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I might have to go back to centOS
Old 03-21-2017, 08:08 AM   #3
Registered: Jun 2014
Posts: 32

Original Poster
Rep: Reputation: Disabled
So this thread never went anywhere. I'm a fairly sophisticated user but could not get a debian VD server to play well between php and mysql, with mysqli or pdo.

I requested a refund and bought a CentOS VD server from another provider. Took a few hours to get 5 websites fired up and running. What was the explanation? I'll never know.
Old 03-21-2017, 08:40 AM   #4
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
man mysql_secure_installation
Old 03-21-2017, 08:46 AM   #5
Registered: Jun 2014
Posts: 32

Original Poster
Rep: Reputation: Disabled
Yes I read those very pages while fighting the first server. Restarted the server with --skip-grant-tables to create users, to set and reset permissions.

For unexplained reasons my second effort with a (latest and greatest) CentOS VD server was a snap. You do have to be more careful with file permissions these days, and host of other things. I like to run fail2ban too. I've done this many times.

This thread would have been more satisfying if I had discovered why I had so much trouble with Debian...........what I did wrong. I use Mint on my desktop. Have been running a CentOS VD server for about 5 years now without trouble.

My one an only try at a Debian VD server wore the tops of my teeth off.

Last edited by pittendrigh; 03-21-2017 at 08:50 AM.
Old 03-21-2017, 08:48 AM   #6
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,233
Blog Entries: 4

Rep: Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260Reputation: 3260
It was a permission issue – nothing more. You should have issued an appropriate GRANT command followed by FLUSH PRIVILEGES. Sorry that the thread got overlooked.
Old 03-21-2017, 08:52 AM   #7
Registered: Jun 2014
Posts: 32

Original Poster
Rep: Reputation: Disabled
I did just that. Quite a few times.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql connect remote as root works, user fails sir-lancealot Linux - Server 2 02-29-2012 09:50 AM
[SOLVED] CentOS 5.5 mysqli support junust Linux - General 3 03-16-2011 10:09 AM
Bluetooth Pairing - hci cc fails, but rfcomm connect works gpecke Linux - Newbie 5 07-20-2009 03:55 PM
CentOS DNS fails on internal network (works on server) ucffool Linux - Networking 1 05-31-2007 02:36 PM
Minor Samba problem -- Connect fails during boot fstab processing, works later PTrenholme Linux - Networking 11 03-24-2006 01:59 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration