安装包下载
本人使用mac,所以相关安装包以mac包为例,官网最新版安装地址下载地址,点击Download跳到下载页面,直接选择No thanks, just start my download即刻。
安装包安装
点击安装包,一路next,安装成功后会有初始密码信息,需要自己记录下来!!!
启动本地MySql Server:
在最新版的MySQL没有MySQLStartupItem.pkg文件,也不能再用sudo/Library/StartupItems/MySQLCOM/MySQLCOM start命令来启动MySQL,可以在系统设置偏好->MySQL->启动MySQL进行启动。
相关配置设置:
# mysql环境变量配置
# 进入
cd ~
# 编辑bash_profile
vim .bash_profile
# 添加Path
export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/loca/mysql/support-files
# 保存
:wq
# 生效
source .bash_profile
# mysql版本查看
mysql --version
# mysql Ver 14.14 Distrib 5.7.30, for macos10.14 (x86_64) using EditLine wrapper
# 登录
# Tip: 登录前需要在偏好设置启动本地mysql Serve,不然会报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysql -u root -p
Enter password: <输入初始密码>
#登录成功
#Welcome to the MySQL monitor. Commands end with ; or \g.
#Your MySQL connection id is 59
#Server version: 5.7.30
# 登录密码修改
set password for 'root'@'localhost' = password('你的密码');
#设置成功
#Query OK, 0 rows affected, 1 warning (0.03 sec)
# 退出mysql
exit;
远程连接数据库Server
默认情况,mysql账号是不允许远程登录,只能在locahost登录,可localhost登录后,更改mysql.user表里的Host值为'%',则可通过远程主机连接。
查看数据库用户表:select host,user,password from mysql.user;
更改Host为'%': update mysql.user set host = '%' where user = 'xxx'
连接方法: mysql -h host -P port -u user -p
mysql -h 10.122.10.122 -P 3306 -u root -p