无法从命令行OSX Yosemite(10.10.5)启动mysql(5.7.10)

时间:2016-01-10 18:58:34

标签: mysql

当我使用System Preferences>MySQL>StartMySQLServer启动mysql时,我可以这样做:

/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> 

我可以看到System Preferences>MySQL>StartMySQLServer创建的mysql进程:

/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$ 

但是在使用System Preferences>MySQL停止服务器后,我无法使用命令行启动mysql服务器(遵循DEMO中的说明):

/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)

没有mysql进程:

/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$

你应该如何从命令行启动mysql服务器?

3 个答案:

答案 0 :(得分:0)

您必须首先启动mysql服务器才能连接。我想你必须启动mysqld守护进程,但我不确定

答案 1 :(得分:0)

我在终端上使用以下命令启动mysql:

mysql.server start  

试一试。

答案 2 :(得分:0)

实际上,你想要的答案是:

1.首先,将你的mysql路径添加到〜/ .bash_profile:

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

保存并打开一个新终端。

2.然后,您可以通过启动/停止/重启mysql(您也可以选择从“系统偏好设置”中的“mysql”启动它或忘记它):

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.启动后,随意使用命令“mysql”