MySQL connection not working on Windows - mysql

Any clue as to why this would not work in a Windows environment?
It works under Linux
function dbLink(){
$host = 'localhost';
$user = '';
$pass = '';
$base = '';
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($base) or die(mysql_error());
}
dbLink();
Thanks

Try 127.0.0.1 instead. Your localhost might be set to something different.
Make sure PHP for windows has php-mysql installed and enabled.

Related

Why won't this Perl DBI/DBD MySQL (MariaDB) connect to locahost work?

use DBI;
my $dbh = DBI->connect ('DBI:mysql:host=localhost;database=test', 'user', 'password')
or die "failed to connect\n";
Results in an error message:
DBI connect('host=localhost;database=test','user',...) failed: Can't connect to MySQL server on 'localhost' (10061) at connect.pl line 3.
using: DBI 1.641, perl v5.26.2 on Windows 10 and running MariaDB 10.2.14
mysqld is running on the computer, and the server can be connected to with the standard "mysql test -u user -p" command
On another PC running Windows 7 with a very similar setup - but with DBI 1.636 - the connect() succeeds with the same perl code. Is is possible that DBI:mysql and Windows 10 aren't compatible?
It seems you have a space after the word "connect", anyway...try this:
my $driver = "mysql";
my $database = "DBname";
my $ip = "localhost";
my $db = "DBI:$driver:DBNAME:$ip:database=$database";
my $username = "mysqluser";
my $password = "mysqlpass";
my $cn = DBI->connect($db, $username, $password)
or print "Couldn't connect to database: " . DBI->errstr . "\n\n";

Can't see PHPMYADMIN Control Panel

I have a problem with PHPMYADMIN. I'm trying to create a database on local with my Mac but this is what I see when I'm inside PHPMYADMIN: http://i.imgur.com/u7hhGwh.png.
As you can see there is no control panel. It seems like I'm not admin of my PHPMYADMIN or maybe I'm just a guest..
This is the config file of my database:
<?php
/*
* Generated configuration file
* Generated by: phpMyAdmin 4.4.8 setup script
* Date: Thu, 04 Jun 2015 15:01:24 +0000
*/
/* Servers configuration */
$i = 1;
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* End of servers configuration */
$cfg['DefaultLang'] = 'it';
$cfg['blowfish_secret'] = '–––––––––––.––––––';
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
$cfg['ServerDefault'] = 1;
?>
This is what I personally did to solve my problem.
Uninstalled and deleted (is important! delete them totally!) mysql and phpmyadmin from the system. You can find mysql in /usr/local on OSX 10.10
Typed in the terminal bash <(curl -Ls http://git.io/eUx7rg) and then Enter
Wait till the end of the download and a simple guided setup will help you re-installing mysql
Now you should have on your Desktop a file named 'MYSQL_PASSWORD' and it will be the password that you will use with phpmyadmin (nickname is root).

Problems with Godaddy Database connections

I am having problem with connecting to Database in godaddy. I do not know is it my code that is giving the problem or godaddy that is giving the problem.
I tried 2 different ways of coding to connect to database;
Below is the working code:
$hostname = "xxx.db.xxx.hostedresource.com";
$username = "xxx";
$dbname = "xxx";
$password = "xxx";
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
Below is the non-working code:
define("DBHOST","xxx.db.xxx.hostedresource.com");
define("DBNAME","xxx");
define("DBUSER","xxx");
define("DBPASS","xxx");
mysql_connect(DB_HOST,DB_USER,DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
Or is it because godaddy can't use define function? Thanks guys.
You're defining DBHOST but using DB_HOST. The same problem with all other defined values as well. define is NOT banned on GoDaddy.

phpMyAdmin - what' swrong with next configuration?

tryin to install phpMyAdmin on my Fedora server, but if i open it in browser, i get next error:
2002 Cannot log in to the MySQL server
file config.inc.php have next content:
<?php
/* Servers configuration */
$i = 0;
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '123';
/* End of servers configuration */
$cfg['blowfish_secret'] = '4c45c50fe8b283.01675296';
$cfg['DefaultLang'] = 'en-utf-8';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
just to add, in mysql i created user root, with password 123, so i can log in with:
mysql -h localhost -u root -p123
can you help me where is the problem?
mysql -h localhost actually connects via unix socket instead of a TCP connection to 127.0.0.1. Explicitly specifying mysql -h 127.0.0.1 on the other hand does use the TCP method.
So what you are testing is a local socket connection, not a network one. Make sure phpMyAdmin uses the same method; the line
$cfg['Servers'][$i]['connect_type'] = 'tcp';
should probably read
$cfg['Servers'][$i]['connect_type'] = 'socket';
Your mysqld probably has either networking disabled or user permissions denying root/123 access from the network.
With -h localhost in your example you are actually connecting over a named socket. You can see for yourself - from the mysql client type "\s":
mysql> \s
--------------
(....)
Connection: Localhost via UNIX socket
ok, i solve it.
in configuration file, i just changed 'localhost' to '127.0.0.1', and it started to work.
tnx anw!

perl script to connect to mysql server port 3307

I am trying to connect to a mysql server which is running at port 3307. How do I connect to the server? I do not see any other way to specify port. I am using like this:
#!/usr/bin/perl
use Mysql;
$host = "localhost";
$database = "abc";
$tablename = "def";
$user = "uuu";
$pw = "ppp";
$connect = Mysql->connect($host, $database, $user, $pw) or die "Cannot connect to MySQL server\n";
I want to use MySQL package and not DBI.
Thank you.
You are mistaken. You want to use DBI and not Mysql. The Mysql module became obsolete 12 years ago, when it was replaced with a compatibility module that's just a wrapper around DBI. Even the compatibility module has been removed from the current distribution; you have to install an old DBD::mysql just to get it (it last shipped in DBD-mysql 3.0008, released back in 2006).
#!/usr/bin/perl
use strict;
use DBI;
my $host = "localhost";
my $database = "abc";
my $port = 3307;
my $tablename = "def";
my $user = "uuu";
my $pw = "ppp";
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port",
$user, $pw)
or die "Cannot connect to MySQL server\n";
Try specifying host like localhost:3307
For me...Following seems to be working ...
#!/usr/bin/perl
use strict;
use DBI;
my $host = "rajeshk-W7";
my $database = "rajesh";
my $port = 3307;
my $tablename = "def";
my $user = "rajesh";
my $pw = "rajesh123";
#my $dbh = DBI->connect("DBI:mysql:rajesh:rajeshk-W7","rajesh","rajesh123") or die "Cannot connect to MySQL server\n";
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",$user, $pw) or die "Cannot connect to MySQL server\n";
where i dint mentioned port. When i add port, its unable to connect.