Mac上配置mysql数据库,遇到了一些配置问题,做个记录。

安装mysql

通过Homebrew命令行安装mysql。

brew install mysql

SQL

将时间戳转换为时间

datetime(time/1000, 'unixepoch', 'localtime') 

eg:
select *, datetime(time/1000, 'unixepoch', 'localtime') from trace_log 

配置mysql

执行mysql的安全配置文件,输入下面命令,回车即可。

/usr/local/bin/mysql_secure_installation

Error

Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

解决方案:

先执行 mysql.server start,会生成mysql.sock文件。

继续执行/usr/local/bin/mysql_secure_installation安全配置命令。

mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N   // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here.

New password:            // 设置密码

Re-enter new password:     // 再一次确认密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    // 移除不用密码的那个账户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

配置完,就可以启动了。

启动mysql

~ mysql -u root -p 

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

//使用某个数据库
use databse_name;

//查看某个数据表的结构
desc table_name;

mysql可视化软件

Mac os x几款mysql客户端

1,Navicat 这是一款可支持多种数据库的客户端,可支持mysql,sqlite,oracle,sql server等数据库。当然也可以选择只支持某种数据库的客户端下载。 软件可以免费使用30天,当然可以在网上下个注册机就可以了。 注册机 下载地址:http://www.navicat.com/download

2,DBeave 无需破解,直接使用,下载只需选择适合自己的版本 下载地址:http://dbeaver.jkiss.org/download/#macos

3,MySQL GUI Tool 这是mysql提供的一款sql客户端工具,可去官网下载 下载地址:http://dev.mysql.com/downloads/tools/workbench/

4,Selquel pro 这是一款免费使用软件下载即可使用 下载地址:http://www.sequelpro.com

当然这些mysql客户端也有windows版本 我用的是第四款,感觉还蛮好的~

参考资料

https://segmentfault.com/q/1010000004078668?_ea=484006

Mac os x下几款mysql客户端:http://blog.csdn.net/lzwglory/article/details/62881909


分享到