How To Connect To MySQL Server After Install XAMPP On Mac OS

XAMPP is a software package which is a bundle of apache, mysql and ftp package. You always need to use it when you develop php + mysql application. It is easy to use on Windows, but when i use it on Mac OS, i meet some errors, this article will tell you how to install, start, stop XAMPP on Mac OS and fix all these errors.

1. How To Install, Start, Stop XAMPP On Mac OS.

First you should download the XAMPP installer for Mac OS. If you find the XAMPP official website https://www.apachefriends.org/ can not be accessed, you can search keyword XAMPP in https://sourceforge.net. and download it there.

After download XAMPP mac os version, double click it to install it. After install, you can start it by click XAMPP icon in finder /Applications folder.

xampp in mac os applications folder

After click XAMPP icon, it will display below popup window. Click Start button to start both apache, mysql and ftp server as service.  Click Stop button to stop it.

click xampp start button to start apache mysql ftp server

After click Start button, you can see the server status and server IP Address at the top area of above window. Please remember the ip address. The server is running in an embed linux server, and the server ip is just the ip address.

Click the Go to Application button will show you the XAMPP dashboard in a popup web browser. Click the Open Terminal button will open a terminal and login to the embedded linux server with root user.

after start xampp, it will display server service and server ip address at window top area

If you want to know where the XAMPP files is installed, you can click the Volumes tab in above XAMPP manager window, then click the Mount button to mount the /opt/lampp directory on XAMPP linux server to local Mac OS, then click Explore button to open XAMPP install folder in popup local Mac finder window. You can copy your WordPress website source files into the htdocs folder to browse it in web browser.

READ :   JDBC Create Table Example Use Statement

mount xampp install folder in xampp manager window

2.How To Fix Can Not Access XAMPP Apache Dashboard Use Localhost Error.

In past, after start XAMPP, we usually access it’s dashboard web page use url http://localhost/dashboard/. But when i use this url, it can not open the page. This is because we are not running web browser in XAMPP embed linux server, we access it in Mac OS.

To access XAMPP apache dashboard, you should use the XAMPP embed Linux server’s ip to replace localhost like this, http://192.168.64.2/dashboard/.

3.How To Fix Can Not Connect To MySQL Server With Root User Error.

To manage the XAMPP MySQL server, you can use MySQL workbench. If you use root user with empty password ( the root user’s password is empty by default ), it will popup error message Failed to Connect to MySQL at 127.0.0.1:3306 with user root. This error is because the MySQL server’s Hostname is wrong, the MySQL server Hostname should be the running XAMPP server’s ip address, which is 192.168.64.2 in this example.

But when you use XAMPP linux server’s ip 192.168.64.2 as the Hostname and use root user with empty password, it will popup another error dialog which said Failed to Connect to MySQL at 192.168.64.2:3306 with user root, Access denied for user ‘root’@’192.168.64.1’ (using password: NO). You can read article How To Resolve Access Denied For User ‘root’@’localhost’ (using Password: Yes) When Connect MySQL Database to fix this, but we had also list the short steps about how to fix it as below.

connect to xampp mysql server failed with root user

To fix this error, you should click the Open Terminal button in XAMPP manager window, then follow below steps to resolve it.

  1. Connect to mysql server in command line with root user, the default root user’s password is empty.
    [email protected]:/# mysql -u root -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 9
    Server version: 10.3.16-MariaDB Source distribution
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> 
    
  2. Select all host and user name from mysql.user table use select sql command like below. We can see that the root user can only connect to the embedded mysql server on localhost, and the localhost is the XAMPP linux server, but MySQL workbench is running on the Mac OS. So you should grant root user access permission to the MySQL server from any machine with ‘%’ as the host value.
    MariaDB [(none)]> select host, user from mysql.user;
    +-----------+-------+
    | host      | user  |
    +-----------+-------+
    | 127.0.0.1 | root  |
    | ::1       | root  |
    | localhost |       |
    | localhost | pma   |
    | localhost | root  |
    +-----------+-------+
    6 rows in set (0.001 sec)
    
  3. But generally, allow root user access MySQL server from any machine is not safety, so we had better create another MySQL user account and make it to connect to MySQL server from any machine remotely.
  4. Create a new MySQL server user account with provided username and password use MySQL CREATE USER command. Please note @’%’ means jerry can connect to MySQL server remotely from any machine.
    CREATE USER 'jerry'@'%' IDENTIFIED BY 'jerry';
  5. Grant all privileges to user account ‘jerry’@’%’.
    GRANT ALL PRIVILEGES ON *.* TO 'jerry'@'%' WITH GRANT OPTION;
  6. Now use above newly created user account to connect to MySQL server. Please note the Hostname should be the MySQL server ip address ( displayed in XAMPP manager window top area ).connect to xampp mysql server use xampp server ip
  7. When you connect to MySQL server successfully, you will get below successful message dialog.
    connect to xampp mysql server successfully from mysql workbench

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.