Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»MacOS»How to Install MySQL on macOS

    How to Install MySQL on macOS

    By RahulJuly 31, 20193 Mins Read

    MySQL is a relational database management system. MySQL is the widely used database server in the world. This tutorial helps you to install MySQL database server on macOS Sierra 10.12 and High Sierra 10.13 and other supported versions using Homebrew.

    Advertisement

    Step 1 – Prerequisites

    Before starting the installation of MySQL using this tutorial you must have the following prerequisites

    • Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application.
    • Homebrew: Homebrew is a popular package management tools used for installing most open source software like Node. Here is the Homebrew installation tutorial

    Step 2 – Install MySQL on macOS

    At this time of writing this tutorial, Homebrew has MySQL 5.7.21 version in its main repository. Start a terminal and run command to install MySQL:

    brew install mysql
    

    Wait for the installation process finish. Now you just need to configure things so that your MySQL server is auto-started

    brew services start mysql
    

    Also, you have to set a strong password for the MySQL root account. Use the following command to set a new password. Make sure to use a strong password.

    mysqladmin -u root password 'newpassword'
    

    Step 3 – MySQL Configuration

    MySQL server has been installed on your system. The binary files are installed under /usr/local/bin directory and all the MySQL related files are created under “/usr/local/var/mysql” directory. The main confiugration file is created at:

    Configuration file:  /usr/local/etc/my.cnf
    

    You can use above file to customize your MySQL server. Now, Connect to MySQL server using the command:

    mysql -u root -p
    
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.21 Homebrew
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Step 4 – Manage MySQL Service

    There are mysql.server command available under /usr/local/bin directory, which is used to manage MySQL service. You can use mysql.server command with options status, stop, start, or restart MySQL service on your system.

    mysql.server status        ## Show status of MySQL
    mysql.server stop          ## Stop MySQL service
    mysql.server start         ## Start MySQL service
    mysql.server restart       ## Restart MySQL service
    

    All done. You have running MySQL server on your system. What next? Visit our MySQL tutorial section to create and manage databases from the command line.

    database MySQL
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    A Comprehensive Guide to Optimizing MySQL Table

    Create a Basic CRUD API in NodeJS, ExpressJS and MySQL

    How to Optimize MySQL Parameters for a 32 GB RAM System

    View 4 Comments

    4 Comments

    1. John on January 31, 2020 1:20 am

      hello. Thanks for this page.
      I can get as far as :
      mysqladmin -u root password ‘newpassword’

      But I always get this error:
      mysqladmin: connect to server at ‘localhost’ failed
      error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’

      any ideas?
      Thanks

      Reply
      • zlaja on May 12, 2021 11:27 am

        mysqladmin -u root – p
        Then in prompt add your password

        Reply
    2. Marco on December 2, 2018 11:36 am

      Thanks 🙂

      Reply
    3. Alex on November 2, 2018 12:17 pm

      Thank You! 🙂

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • A Comprehensive Look at the Simple Mail Transfer Protocol (SMTP)
    • Understanding Basic Git Workflow: Add, Commit, Push
    • The Difference Between Git Reset –soft, –mixed, and –hard
    • Understanding the Staging Area in Git’s Workflow
    • Python Function with Parameters, Return and Data Types
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.