Leonard Teo
Leonard Teo

Reputation: 1278

Cannot log in to mysql after default install with Macports

I've installed mysql5 using Macports and the installation appears to check out but I cannot login to the server at all.

This is what I did:

sudo port install mysql5-server

This builds and installs fine.

sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

This runs fine as well. It outputs the following:

Installing MySQL system tables... OK Filling help tables... OK

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password' /opt/local/lib/mysql5/bin/mysqladmin -u root -h LeoMacBook.local password 'new-password'

Alternatively you can run: /opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with: cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

Now...let's follow the instructions exactly. I start the server:

sudo /opt/local/lib/mysql5/bin/mysqld_safe &

Server is running fine.

When I try to change the root password, I CANNOT log in.

LeoMacBook:bin leonardteo$ /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password' /opt/local/lib/mysql5/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'

I'm at wits end.

I've started the server with --skip-grant-tables. With this, I can load up mysql fine from the command line and I'm connected to the server. When I run SELECT * FROM mysql.user;, it returns an empty set! With this, I've tried to create a new user by invoking the command:

CREATE USER 'root'@'localhost' IDENTIFIED BY 'root';

But this doesn't work. I get the error:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

I cannot get this working. It seems I am so close, yet the root user seems to be missing.

Any ideas?

Leonard

Upvotes: 2

Views: 1814

Answers (1)

Marc B
Marc B

Reputation: 360562

Once you've started up mysql with --skip-grant-tables, issue a flush privileges; query. This'll re-enable the permissions system and allow you to run the usual grant and create user queries.

Upvotes: 4

Related Questions