OSX 10.13.2 High Sierra
mariadb 10.2.12
当我尝试使用用homebrew安装的mariadb
时,我遇到了完全相同的错误。在安装后,我做的第一件事是:
$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2)
为了解决问题,我进行了以下操作:
~$ which mysql
/usr/local/mysql/bin/mysql
然后我尝试了:
~$ mysql -u 7stud -p test
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
并且:
~$ mysql -u -p
ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
解决方案:
~$ mysql.server start
Starting MySQL
.180127 00:24:48 mysqld_safe Logging to '/usr/local/var/mysql/MyMBP.home.err'.
180127 00:24:48 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
SUCCESS!
~$ mysql -u root
Welcome to the MySQL monitor. Commands end with
Your MySQL connection id is 9
Server version: 5.5.5-10.2.12-MariaDB Homebrew
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
mysql>
Okay, let's go:
mysql> show databases
-> ;
+
| Database |
+
| information_schema |
| mysql |
| performance_schema |
| test |
+
4 rows in set (0.01 sec)
mysql> CREATE DATABASE my_db;
Query OK, 1 row affected (0.00 sec)
mysql> use my_db;
Database changed
mysql> show tables;
Empty set (0.01 sec)
mysql> CREATE TABLE people (
-> id INT(12) not null auto_increment primary key,
-> name VARCHAR(40),
-> info VARCHAR(100)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> describe people;
+
| Field | Type | Null | Key | Default | Extra |
+
| id | int(12) | NO | PRI | NULL | auto_increment |
| name | varchar(40) | YES | | NULL | |
| info | varchar(100) | YES | | NULL | |
+
3 rows in set (0.01 sec)
mysql> INSERT INTO people(name, info) VALUES("Joe", "a b c") ;
Query OK, 1 row affected (0.01 sec)
mysql> select * from people;
+
| id | name | info |
+
| 1 | Joe | a b c |
+
1 row in set (0.00 sec)
mysql> INSERT INTO people(name, info) VALUES("Beth", "1 2 3") ;
Query OK, 1 row affected (0.00 sec)
mysql> select * from people;
+
| id | name | info |
+
| 1 | Joe | a b c |
| 2 | Beth | 1 2 3 |
+
2 rows in set (0.00 sec)
mysql> quit
Bye
~$ mysql.server stop
Shutting down MySQL
. SUCCESS!
~$
我在自动启停MariaDB文档中找到了最佳的手动启动和停止Mariadb的指令:
You have the option of starting the mysqld server several different
ways:
Run or invoke mysqld itself. An example of doing this is described more in Running MariaDB from the Source Directory.
Use the mysqld_safe startup script
Use the mysql.server startup script
The mysql.server script starts mysqld by first changing to the MariaDB
install directory and then calling mysqld_safe. Adding an appropriate
user line to the [mysqld] group in your my.cnf file will cause the
server to be run as that user.
If you have installed MariaDB to a non-standard location, you may need
to edit the mysql.server script to get it to work right.
mysql.server works as a standard SysV-style init script. As such you
use the script with start and stop arguments like so:
mysql.server start
mysql.server stop