MAC brew install 安装Mysql

2020-06-21  本文已影响0人  码而优则仕

MAC brew install 安装Mysql

首先是下载安装mysql

brew search mysql 查看所有版本mysql

brew install mysql安装最新版本mysql brew install mysql@版本

安装好之后进入mysql 脚本目录

cd /usr/local/Cellar/mysql/8.0.19_1/bin/

wushuanuandeMBP:bin wsq$ sudo mysql.server start

Starting MySQL

.Logging to '/usr/local/var/mysql/wushuanuandeMBP.lan.err'.

 ERROR! The server quit without updating PID file (/usr/local/var/mysql/wushuanuandeMBP.lan.pid).

启动时会提示上面的错误,原因是相应文件夹没有权限,设置一下权限:

sudo chmod -R 777 /usr/local/var/mysql/

然后再启动mysql

wushuanuandeMBP:bin wsq$ sudo mysql.server start

Starting MySQL

.Logging to '/usr/local/var/mysql/wushuanuandeMBP.lan.err'.

. SUCCESS! 

项目启动成功!

接下来是设置数据库密码

wushuanuandeMBP:bin wsq$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

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) : 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 -u root -p

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

默认的数据库是mysql系统内部自带的,可以自己创建自己的数据库

mysql> create database mydatabase
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydatabase         |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
mysql> use mydatabase;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> 

-- 退出mysql
mysql> exit;
Bye

重启mysql服务器

wushuanuandeMBP:bin wsq$ sudo mysql.server restart
Password:
Shutting down MySQL
.. SUCCESS! 
Starting MySQL
. SUCCESS! 

停止mysql服务器

wushuanuandeMBP:bin wsq$ sudo mysql.server stop
Shutting down MySQL
.. SUCCESS! 

也可以使用可视化客户端进行连接使用。

上一篇下一篇

猜你喜欢

热点阅读