osx中安装mysql数据库

Posted rage_angel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osx中安装mysql数据库相关的知识,希望对你有一定的参考价值。

1、安装mysql

brew install mysql

2、启动或关闭mysql

brew services start mysql(启动)或 mysql.server start brew services stop mysql(停止)

3、mysql相关权限配置

3.1、执行:/usr/local/Cellar/mysql/5.7.14/bin/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: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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) : n

 ... skipping.


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) : y
Success.

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! 
3.2、创建数据库
mysql -u root -p 以root权限进入
create database test; 创建数据库语句
drop database test; 删除数据库语句
show databases;显示数据库

create user 'yourusername'@'127.0.0.1/localhost' identified by 'yourpassword’; 创建用户
GRANT ALL ON test.* TO '<span style="font-family: -webkit-standard;">yourusername</span>'@‘127.0.0.1/localhost' IDENTIFIED BY 'yourpassword’; 给用户授权
select user,host from mysql.user; 查询用户及端口
select user(),current_user(); 查询用户

mysql -u youusername -p 以用户权限进入


参考: python使用mysql数据库

以上是关于osx中安装mysql数据库的主要内容,如果未能解决你的问题,请参考以下文章

在OsX Leopard中安装SQLite3

无法在OSX 10.11中安装CocoaPods

使用 torch-cl 在 OSX 中安装 zerobrane 火炬包的正确路径?

在 Anaconda 中安装 Kivy

ini 我的自定义tmux配置可以提高工作效率。别忘了在OSX中安装reattach-to-user-namespace以便复制粘贴工作。

如何使用 Pip (OS X) 在虚拟环境中安装 Python 包