Mac下mysql的安装与卸载 配置初始化密码修改
第一:首先去官网网站下载Mysql软件
https://downloads.mysql.com/archives/community/
记住选择对应系统的版本
第二:安装dmg文件,完成之后会产生一个随机的密码,不需要记住,后面会说到
第三:配置环境变量,我们输入mysql -u root -p 是显示 not commond
配置环境变量
用文本编辑器打开 .bash_profile 文件
- vim ~/.bash_profile
加入下面的命令
- PATH=$PATH:/usr/local/mysql/bin
并保存修改
- vim 中先按 Esc键,在输入 :wq
更新配置文件
- source ~/.bash_profile
现在输入mysql相关的命令就能显示了 例如:mysql --version
发现另外一个终端输入myslq --version还是显示 zsh: command not found: mysql 错误
看链接解决
第四:mysql初始化安装密码修改步骤
(1)先停止mysql服务。 命令或者手动停止服务
- sudo /usr/local/mysql/support-files/mysql.server stop
顺便附上其他mysql常用的服务命令
启动MySQL服务
- sudo /usr/local/MySQL/support-files/mysql.server start
重启MySQL服务
- sudo /usr/local/mysql/support-files/mysql.server restart
(2)在终端使用命令sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables,以安全模式启动mysql服务
- sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
(3)打开另一个终端
(4)在终端执行命令sudo /usr/local/mysql/bin/mysql -u root(此时要求输入的密码为用户开机密码)
- sudo /usr/local/mysql/bin/mysql -u root
(5)在终端执行修改密码命令
- UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE User='root';
// 或 (建议第一个命令)
- UPDATE mysql.user SET Password =PASSWORD('123456') WHERE User='root';
到这里就能完成了正常登录了,如果在终端输入mysql --version 显示
(6)使用修改之后的密码登录进去,接下来当然就是想看看数据库有哪些了
- show databases;
- 你会发现报错了,如下
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决办法
1、 修改用户密码
- mysql> alter user 'root'@'localhost' identified by 'youpassword';
或者
- mysql> set password=password("youpassword");
2、刷新权限
- mysql> flush privileges;
3.help帮助
- mysql> help contents
You asked for help about help category: "Contents"
For more information, type 'help <item>', where <item> is one of the following
categories:
Account Management
Administration
Compound Statements
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Help Metadata
Language Structure
Plugins
Procedures
Storage Engines
Table Maintenance
Transactions
User-Defined Functions
Utility
4.显示数据库
- mysql> show databases;
默认的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
到这里就完成了mysql的所有安装及其修改原始密码的步骤
Mysql数据库的卸载,记住先先停止所有mysql有关进程。
1 sudo rm /usr/local/mysql
2 sudo rm -rf /usr/local/mysql*
3 sudo rm -rf /Library/StartupItems/MySQLCOM
4 sudo rm -rf /Library/PreferencePanes/My*
5 vim /etc/hostconfig
6 rm -rf ~/Library/PreferencePanes/My*
7 sudo rm -rf /Library/Receipts/mysql*
8 sudo rm -rf /Library/Receipts/MySQL*
9 sudo rm -rf /var/db/receipts/com.mysql.*