Search code examples
mysqlmacosrootosx-elcapitan

OS X El Capitan: MySQL errors always keep. There's no use to solve it


Before, I have researched many questions related to my problem at Stackoverflow, but none of these questions answers solved my problems. The following questions:

  1. Initial authorization issue in mysql
  2. MySQL: How to fix access denied for user 'root'@'localhost'?

I followed the tutorial: Installing Apache, PHP, and MySQL on Mac OS X El Capitan

Follow the terminal:

Gustavo-Maci:mysql gus$ export PATH=/usr/local/mysql/bin:$PATH
Gustavo-Mac:mysql gus$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: NO)
Gustavo-Mac:mysql gus$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Gustavo-Mac:mysql gus$ set password for 'root'@'localhost' = PASSWORD('kartuli')
-bash: syntax error near unexpected token `('
Gustavo-Mac:mysql gus$ 

I use OS X El Capitan 10.11 on a Mac mini with HDs of OSes Phoenix and Windows 10.

Update

I followed the video tutorial, but I got an error:

Gustavo-Mac:~ gus$ export PATH=/usr/local/mysql/bin:$PATH
Gustavo-Mac:~ gus$ mysql -u root ;
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Solution

  • I solved my problem! I followed the @eli's answer at the question MySQL user DB does not have password columns - Installing MySQL on OSX. Only that I had to use sudo to stop and start mysqld and after I followed these commands. The updated tutorial for El Capitan and later users:

    Stop MySQL Server:

    sudo /usr/local/mysql/support-files/mysql.server stop
    

    Start the server in safe mode with privilege bypass:

    sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
    

    Open a new terminal window:

    sudo /usr/local/mysql/bin/mysql -u root;
    
    UPDATE mysql.user SET authentication_string=PASSWORD('your password') WHERE User='root';
    
    FLUSH PRIVILEGES;
    

    Exit the mysqld:

    \q
    

    Then stop the MySQL Server again:

    sudo /usr/local/mysql/support-files/mysql.server stop
    

    Start and export mysql:

    export PATH=/usr/local/mysql/bin:$PATH
    

    To get new strong password to replace your new password for installing MySQL:

    mysql_secure_installation
    

    Start the MySQL Server:

    sudo /usr/local/mysql/support-files/mysql.server start
    

    If you want to install phpMyAdmin, firstly use git and after you need to sudo for extracting the compacted archive to the restricted folder:

    cd /Library/WebServer/Documents/; sudo curl -O https://files.phpmyadmin.net/phpMyAdmin/4.6.3/phpMyAdmin-4.6.3-all-languages.zip
    sudo mv phpMyAdmin-4.6.3-all-languages/ phpmyadmin
    cd phpmyadmin
    sudo mv config.sample.inc.php config.inc.php
    

    Enter http://localhost/phpmyadmin/ and use the user and the password that you have done during mysql_secure_installation.

    Voilà. ;-)