create mysql database on mac os x - php

I know this sounds a little ridiculous, but I'm just honestly wondering how I can create a MySQL database on my Mac OS X machine. I have MySQL installed (as far as I know) as well as PHP, and I'm wondering how I can create one.
I have downloaded a sample PHP ecommerce site to kind of delve into what I'm trying to familiarze myself with, and the PHP files are attempting to connect to a nonexistant database, which I'm hoping to create right now.
Do they have an extension of .sock? Because, here is the "error" code when I try to test a PHP page referencing the nonexistant database:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in< /Library/WebServer/Documents/plaincart/library/database.php on line 4 Warning: mysql_connect(): No such file or directory in
/Library/WebServer/Documents/plaincart/library/database.php on line 4 MySQL connect failed. No such file or directory

My guess is you are specifying the database server as localhost somewhere. Try 127.0.0.1 instead.

I had this problem once with WordPres on Mac OS X. The answer was to name the local machine in the db connection configuration 'Localhost' with capital 'L', because on OS X localhost != Localhost.

I had the same problem with MySQL on the OSX. It turned out that the MySQL server was actually set up to use a different socket than the default setting in PHP.
PHP was looking in /var/mysql/mysql.sock, while mysql was creating the socket in /tmp/mysql.sock.
I fixed it by editing the php.ini and set mysql.default_socket = /tmp/mysql.sock

Related

Connecting to MYSQLi through Terminal in Mac OS using MAMP

I am trying to run my PHP script via Terminal in Mac. When I try to run the script, I am getting this error:
Warning: mysqli_connect(): (HY000/2002): No such file or directory
This is how I am trying to connect:
mysqli_connect('localhost','root','root','my_db');
I also tried to connect using the host: 127.0.0.1 instead of localhost and I then got this error:
Warning: mysqli_connect(): (HY000/2002): Connection refused
From what I've read online it might have something to do with mysql socket, but whatever I try to do to get this to work doesn't help.
I even tried to connect using the following as my host:
:/Applications/MAMP/tmp/mysql/mysql.sock
:/var/mysql/mysql.sock
Any idea what can be the problem/solution?
Had the same issue. Here's what I did.
Open Terminal (/Applications/Utilities/terminal.app)
Use your favorite text editor to create/edit ~/.bash_profile. For instance, if you're using vim, type vim ~/.bash_profile. I use TextMate, so I typed mate ~/.bash_profile.
Add these lines:
export MAMP_SQL=/Applications/MAMP/Library/bin
export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.10/bin
export PATH="$MAMP_SQL:$MAMP_PHP:$PATH"
These lines ensure that the first versions of MySQL and PHP that are found (and therefore used) are the versions used by MAMP. NB: Make sure that php5.5.10 matches the version MAMP is using. You can check this against http://localhost:8888/MAMP/index.php?page=phpinfo&language=English by default. SAVE THE FILE (I shouldn't have to save this, but invariably someone complains that it doesn't work).
Close your terminal window and reopen. This restarts the shell, which will load your .bash_profile script.
Type which php. You should get something akin to /Applications/MAMP/bin/php/php5.5.10/bin/php
Type which mysql. You should get something akin to /Applications/MAMP/Library/bin/mysql
If for any reason you get something different than the responses from 5 and 6, go back and check your .bash_profile; chances are you just neglected to save it properly.
If you have MySQL installed on your computer, you can do the following command:
mysql -u "username"
replacing "username" with the username of your computer
NOTE: often times root does not work, try the username of your computer

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla
uploaded all the files to the server side public html and tried to run the file in browser
by using: my_school_link/my_username/
and I have this error
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
<?php
mysql_connect('host_name', 'user_name', 'password');
mysql_select_db('my_database_name');
?>
I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*
and I have tried the following
view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
have entered the correct hostname, username and password
run as admin
checked if mysql is running ( it is so is Apache)
MySQL socket specified in php.ini was never edited so it is in default mode
cant locate mysql config file, or my.cnf, or etc folder
What could the problem be? Please if anyone could help me, please tell me what's wrong.
Please provide a step-by-step guide. and file extensions if need to save files....
Is there any additional things i can add to help anyone understand my problem better?
if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)
If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
Another reason may be that you are using the wrong host name while connect.
Don't use mysql_connect it is deprecated and instead you should use MySqli

connect to mySQL using xampp

Im using xampp control on macbook and trying to connect to 'localhost/phpmyadmin'. I have apache and mySQL both running but im getting an error
#1 - Can't create/write to file '/var/folders/kb/6g_npz7s1511w39k7v224gq80000gn/T/#sql4e6_1_2.MYI' (Errcode: 13)
Any ideas about what this might be or how i could connect?
Usually you'd get that error because the directory that MySQL is using to write temp files to isn't writeable by the mysql user; usually that directory would be /var/tmp or something similar. Try starting mysql with the --tmp-dir=/var/tmp and see if it still complains. See http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_tmpdir
check the port of the apache .... by selecting checkport ... and in the browser set the url as: localhost:(port number)/phpmyadmin

Having troubles configuring PHP to work with mySQL

I'm venturing out of the world of .NET and into the world of open-source. However, I've hit a few roadblocks while trying to get my development environment set up. And I'm kind of stuck on the most recent one.
I have installed: Apache 2.2, php 5.3.2, and mySQL 5.1.48
everything is working pretty much; apache is serving up PHP pages, and I'm able to create databases and tables in mySQL, however, I can't seem to get php to communicate correctly with mySQL. My php.ini has these lines un-commented:
extension=php_mysql.dll
extension=php_mysqli.dll
However, I keep getting this error message:
Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysql_test.php on line 15
any help would be greatly appreciated.
(btw, the php code runs properly when I put it on my web host)
This is most likely a configuration problem with the MySql server. It sounds like it either isn't listening on the correct port or something else is going on with the connection. You have the extensions loaded correctly because PHP is able to find the mysql functions. I would make sure you don't have a firewall blocking any of the requisite ports (actually, just try turning off your firewall and see what happens...just don't forget to turn it back on ;-) ). Also make sure if you are following a tutorial you didn't deviate from the MySQL setup instructions at all. If those don't work, post an update and we can try again.
This looks like bug #45150 : MySQL functions cannot be used with 5.3.x on Vista when using "localhost" -- I've had this problem once, and it took me some time to figure out what was causing it...
If you are working with Windows Vista (and possibly seven ?), and trying to connect to MySQL using "localhost" as host, try to replace that by the corresponding IP address : "127.0.0.1"
Or try to edit the hosts file, and to un-comment the line that corresponds to localhost in IPv4 :
127.0.0.1 localhost
(Remove the # at the beginning of the line)
Or to comment the line that corresponds to localhost in IPv6 :
#::1 localhost
(Add a # at the beginning of the line)
And here's an interesting article about that : PHP 5.3 and MySQL connectivity problem
Use XAMPP - it'll remove any headaches like this for local development.
XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin.

Warning: mysql_connect(): Can't connect to local MySQL server

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) in /home/aa/public_html/bb/db.php on line 2
Could not connect:
iam getting this error but the problem is that this error comes irregularly,sometimes it didnt come all the day and sometimes it comes countless times.
what could be the possible reason for this?????
That could mean that MYSQL is down or you use the wrong host name while connect. One more possible reason for that could be difference in socket configuration of php against mysql, you can check it in by looking at entry socket in mysql config. file and by looking at output of phpinfo(), you need just to compare it. Or it could that someone else on your machine also using that socket.
PS. As well my wild guess, go through your code and check you always get your connection close right and all your queries as well.
Make sure that your MySQL is running.
OR
Create a file called: phpinfo.php with the following inside it:
<?php phpinfo(); ?>
Load the file in your browser: http://localhost/phpinfo.php and scroll down for mysql. Look for the MYSQL_SOCKET and make sure it matches your entry in your my.cnf file.
FYI, my my.cnf file is located in: /etc/my.cnf and it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock

Categories