0

When I start mysql using System Preferences>MySQL>StartMySQLServer, then I can do this:

/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ./mysql -uroot -p
Enter password: <password shown me during installation>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.10

Copyright (c) 2000, 2015, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'my new password';
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> 

And I can see the mysql process created by System Preferences>MySQL>StartMySQLServer:

/Library/LaunchDaemons$ ps -e | grep mysql
 1735 ??         0:00.31 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
 1743 ttys000    0:00.00 grep mysql
/Library/LaunchDaemons$ 

But after stopping the server using System Preferences>MySQL, I am unable to start the mysql server using the command line (following the instructions in the docs):

/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ./mysql -uroot -p
Enter password: <new password>
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

There's no mysql process:

/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$ ps -e | grep mysql
 1920 ttys001    0:00.00 grep mysql
/usr/local/mysql-5.7.10-osx10.9-x86_64/bin$

How are you supposed to start the mysql server from the command line?

7stud
  • 46,922
  • 14
  • 101
  • 127

3 Answers3

0

You have to start the mysql server first before you can connect. I think you you must start mysqld daemon but i am not sure

baliman
  • 588
  • 2
  • 8
  • 27
0

I use following command on terminal to start mysql:

mysql.server start  

Give it a try.

Aamir
  • 16,329
  • 10
  • 59
  • 65
0

Actually, the answer you want is:

1.first, add your mysql path to ~/.bash_profile:

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

Save it and open a new terminal.

2.Then, you can start/stop/restart mysql by,(you can also choose to start it from the "mysql" in "system preferences" or to forget it):

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

3.After you start, use command "mysql" at your will~

zhenbo xu
  • 547
  • 5
  • 10