sharon Hwk sharon Hwk - 6 months ago 8
SQL Question

Installing MySQL on a mac

i have downloaded and installed

mySQL
my double clicking on its icon. It was installed successfully.

When i goto startup and preference i see the icon of mysql added and when i click on it i see a screen where it says 'MySQL server instance is running'.

But when i open terminal and
cd
to
/usr/local/mysql
and then when i type
sudo ./bin/mysqld_safe
i was prompted for a password. and i have not added a password when i installed mySQL, so i tried leaving it blank, and then i tried various passwords to login but all attempts failed.

So now i need to know how to login to mySQL via the terminal ?

mysql version - 5.5.24-osx10.6x86_64
my Mac OS - 10.7.3

Answer

What I found installing mysql on MacOs, there are a few differences. One is that it installs it without a password. The other thing is that it by default allows for anonymous logins.

Use this to set the password:

mysqladmin -u root -h localhost password yourpassword

You can remove anonymous logins this way:

shell> mysql -u root -p
Enter password: (enter root password here)
mysql> DROP USER ''@'localhost';
mysql> DROP USER ''@'host_name';

The other thing is that I found that the install does not modify the path variable. What I did to run mysql from the command line was to add /usr/local/mysql/bin to path by adding it to /etc/paths or /etc/paths.d . This may be what you need in order to run mysql. Like someone said in the comments, mysqld_safe is one way to start the mysql server, and it seems that is already set to run.

Here are specific instructions to add something to /etc/paths.d

$ cd /etc/paths.d
$ cat > mysql
/usr/local/bin/mysql

(and then type Ctrl-D that should put a file there)

you may have to sudo if you do not have permissions.

Comments