本文共 2663 字,大约阅读时间需要 8 分钟。
在mac下安装mysql使用对密码的修改,常常忘记和屡次修改之后不知道使用的密码是什么,新安装的mysql使用的是空密码,使用的操做能够解决问题mysql
安装mysql:web
brew install mysql
Updating Homebrew...
Warning: mysql 8.0.12 is already installed and up-to-date
To reinstall 8.0.12, run `brew reinstall mysql`
mac下对mysql的启动、重启、中止操做命令sql
➜ ~ brew info mysql :查看数据库的基本信息
We’ve installed your MySQL database without a root password. To secure it run:
修改mysql密码策略数据库
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
查找mysql进程,查看mysql安装路径安全
ps -ef | grep mysql
使用下面的命令能够查看到mac电脑上安装mysql数据库时使用到的数据库信息,
启动的服务名称:/usr/local/Cellar/mysql/8.0.12/bin/mysqld
–basedir数据库存放的位置,
–plugin-dir插件的目录,
–log-error日志错误文件,
–pid-file进程文件服务器
➜ ~ ps aux | grep mysql
/usr/local/Cellar/mysql/8.0.12/bin/mysqld
--basedir=/usr/local/Cellar/mysql/8.0.12
--datadir=/usr/local/var/mysql
--plugin-dir=/usr/local/Cellar/mysql/8.0.12/lib/plugin
--log-error=cangckdeMacBook-Pro.local.err
--pid-file=/usr/local/var/mysql/cangckdeMacBook-Pro.local.pid
进入mysql安装路径 /usr/local/Cellar/mysql/8.0.11/binsvg
cd /usr/local/Cellar/mysql/8.0.11/bin
暂停mysql服务ui
mysql.server stop
修改密码策略,查看密码策略变量,不一样的版本使用的变量是不一致的,能够使用下面的变量来查看当前数据库中使用的策略变量插件
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
修改密码安全策略rest
PolicyTests Performed
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; numeric, lowercase/uppercase, and special characters; dictionary file
密码策略能够设置的值,1,2,3不一样的安全级别和使用的密码限制长度
set global validate_password.policy=0;
set global validate_password.length=1;
安全模式启动mysql
mysqld_safe --skip-grant-tables &
use mysql
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
注意:重启mysql
mysql.server stop
mysql.server start
进入mysql交互模式
mysql -u root -p newpassworld
mysql默认只容许本地主机访问,修改设置运行外部程序能够访问电脑上的数据库
需更改 mysql 数据库里的 user表里的 host项
把localhost改称%
登陆mysql服务器,执行如下命令
mysql>use mysql;
mysql>update user set host = ‘%’ where user =’root’;
mysql>flush privileges;
mysql>quit
MySQLWorkbench 图形化界面操做数据库
转载地址:http://qqqhp.baihongyu.com/