Install MySQL
- Here are the instructions for installing MySQL on a MacOS by using
homebrew
.
- First, ensure that
homebrew
is up to date and ready to brew
brew update |
- Installed mysql
brew install mysql |
- Run the commands that brew suggested
Try it first:mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
IF HAVING ERRORmysql_install_db: [ERROR] unknown variable 'tmpdir=/tmp'
TRY THIS INSTEADmysqld -initialize --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
- Start MySQL server
mysql.server start |
- MySQL configuration
mysql_secure_installation |
Add the following my.cnf file to /etc:
## The MySQL database server configuration file. |
- Go to MySQL console
mysql -h localhost -u root -p |
- Create database
create database dbName; |
- Create user
create user username@localhost identified by 'password'; |
- Grant privilege
GRANT ALL PRIVILEGES ON newpal.* TO username@localhost WITH GRANT OPTION; |
Some commands:
Restart the MySQL server
mysql.server restart |
Stop MySQL servermysql.server stop
- Check if a MySQL instance is runnig
ps ax | grep mysql |
- Check MySQL status
mysqladmin -u root -p status |
- Changing the permission to MySQL folder. If you are working locally, you can try:
sudo chmod -R 755 /var/lib/mysql/ |
- Export MySQL DB
mysqldump -u dbName1 -p dbName2 > fileName.sql
Note: The
.sql
file might be large. You maygzip
it and then usesftp
to get it back
- Import MySQL DB
mysql -h ip_address -u username -p dbName < fileName.sql |
Remove MySQL
brew remove mysql |