本篇文章带大家简析下mac安装mysql的方法,介绍一下mysql的一些知识,希望对大家有所帮助!
mac如何安装mysql?下载地址:https://downloads.mysql.com/archives/community/
百度网盘下载:链接:https://pan.baidu.com/s/1ncefzjkk7_djh2guatvgww 密码:qm5z
安装双击下载好的dmg文件,会弹出pkg弹框,再双击pkg图标,进入安装界面,在安装界面上一路继续,就安装成功了。
环境变量第一步,在终端切换到根目录,编辑./.bash_profile文件
➜ ~ cd ~➜ ~ vim ./.bash_profile
第二步,进入vim编辑环境,按下i进入insert模式,输入
export path=$path:/usr/local/mysql/binexport path=$path:/usr/local/mysql/support-files
第三步,按下 esc 退出 insert 模式,输入 :wq 保存配置文件
:wq
第四步,在终端界面输入以下命令,让配置文件的修改生效,并查看环境变量是否设置成功
➜ ~ echo $path/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin➜ ~ source ~/.bash_profile ➜ ~ echo $path /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/mysql/support-files➜ ~
mysql服务的启停和状态的查看查看mysql的服务状态
➜ ~ sudo mysql.server statuspassword: error! mysql is not running
启动mysql服务
➜ ~ sudo mysql.server start starting mysql.logging to '/usr/local/mysql/data/mj.local.err'. success!
停止mysql服务
➜ ~ sudo mysql.server stop shutting down mysql. success!
重启mysql服务
➜ ~ sudo mysql.server restart error! mysql server pid file could not be found!starting mysql. success!
启动第一步,终端界面下输入
➜ ~ sudo mysql.server start starting mysql.logging to '/usr/local/mysql/data/mj.local.err'. success!
第二步,启动mysql服务,启动成功后继续输入
➜ ~ mysql -u root -p
第三步,直接回车,进入数据库,看到以下欢迎界面
enter password: welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 1server version: 5.6.41 mysql community server (gpl)copyright (c) 2000, 2018, oracle and/or its affiliates. all rights reserved.oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners.type 'help;' or '\h' for help. type '\c' to clear the current input statement.mysql>
备注:默认安装成功后没有初始密码,所以密码不用输入,直接回车即可。
初始化设置设置初始密码,进入mysql数据库之后执行下面的语句,设置当前root用户的密码为root
➜ ~ mysql -u root -penter password: welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 2server version: 5.6.41 mysql community server (gpl)copyright (c) 2000, 2018, oracle and/or its affiliates. all rights reserved.oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners.type 'help;' or '\h' for help. type '\c' to clear the current input statement.mysql> set password = password('root');query ok, 0 rows affected (0.01 sec)mysql>
退出mysql的界面
mysql> exitbye➜ ~
配置进入到 /usr/local/mysql/support-files目录,里面有个文件my-default.cnf
➜ ~ cd /usr/local/mysql/support-files➜ support-files lltotal 64-rwxr-xr-x 1 root wheel 1.1k 6 15 2018 binary-configure-rw-r--r-- 1 root wheel 773b 6 15 2018 magic-rw-r--r-- 1 root wheel 1.1k 6 15 2018 my-default.cnf-rwxr-xr-x 1 root wheel 894b 6 15 2018 mysql-log-rotate-rwxr-xr-x 1 root wheel 10k 6 15 2018 mysql.server-rwxr-xr-x 1 root wheel 1.0k 6 15 2018 mysqld_multi.server➜ support-files
将目录下的my-default.cnf文件复制到桌面上,改名为my.cnf,
➜ support-files lltotal 64-rwxr-xr-x 1 root wheel 1.1k 6 15 2018 binary-configure-rw-r--r-- 1 root wheel 773b 6 15 2018 magic-rw-r--r-- 1 root wheel 1.1k 6 15 2018 my-default.cnf-rwxr-xr-x 1 root wheel 894b 6 15 2018 mysql-log-rotate-rwxr-xr-x 1 root wheel 10k 6 15 2018 mysql.server-rwxr-xr-x 1 root wheel 1.0k 6 15 2018 mysqld_multi.server➜ support-files cp my-default.cnf /users/a1/desktop/my.cnf
将内容替换为下面的内容
[mysqld]default-storage-engine=innodbcharacter-set-server=utf8port = 3306[client]default-character-set=utf8
将修改后的my.cnf文件复制到/etc目录下,重启mysql
➜ /etc cp /users/a1/desktop/my.cnf ./cp: ./my.cnf: permission denied➜ /etc sudo cp /users/a1/desktop/my.cnf ./password:➜ /etc lltotal 1064......-rw------- 1 root wheel 7.3k 2 29 14:10 master.passwd-rw-r--r-- 1 root wheel 1.2k 5 17 17:24 my.cnf-rw-r--r-- 1 root wheel 11b 2 29 14:43 nanorc-rw-r--r-- 1 root wheel 53b 2 29 14:09 networks......➜ /etc
备注:拷贝文件到etc目录需要系统权限,因此需要在命令前加sudo
检测修改结果
➜ ~ mysql -u root -penter password: welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 4server version: 5.6.41 mysql community server (gpl)copyright (c) 2000, 2018, oracle and/or its affiliates. all rights reserved.oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners.type 'help;' or '\h' for help. type '\c' to clear the current input statement.mysql> show variables like '%char%';+--------------------------+-----------------------------------------------------------+| variable_name | value |+--------------------------+-----------------------------------------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server | latin1 || character_set_system | utf8 || character_sets_dir | /usr/local/mysql-5.6.41-macos10.13-x86_64/share/charsets/ |+--------------------------+-----------------------------------------------------------+8 rows in set (0.01 sec)mysql>
备注:此时不输入密码就登录不了数据库了,必须使用修改后的密码登录数据库了,并且数据库的字符集编码信息已经修改了。
至此,就可以愉快的使用数据库了!!!
推荐学习:《mysql视频教程》
以上就是步骤分明地教你在mac上安装mysql的详细内容。