sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_secure_installation
执行:
systemctl status mysql.service
结果大致如下:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
Active: active (running) since Fri 2017-04-28 17:51:40 UTC; 10min ago
Main PID: 19482 (mysqld)
CGroup: /system.slice/mysql.service
└─19482 /usr/sbin/mysqld
Apr 28 17:51:39 vultr.guest systemd[1]: Starting MySQL Community Server...
Apr 28 17:51:40 vultr.guest systemd[1]: Started MySQL Community Server.
如果没有运行,执行sudo systemctl mysql start
启动
/etc/mysql/my.cnf
将bind-address
从127.0.0.1
修改为0.0.0.0
表示允许所有IP连接,或者指定连接 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
IDENTIFIED BY 'your_root_password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
sudo service mysql restart
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON <database> . <table> TO '<username>'@'localhost';
其中database和table可以是*,表示所有FLUSH PRIVILEGES;
下载MAC MySQL5.6安装文件包解压得到.dmg
文件
查看详细安装文档
按照前面的方法安装完成之后
vim ~/.bash_profile
, 输入以下内容,保存
```
PATH=$PATH:/usr/local/mysql/binexport PATH
2. 重新打开终端执行: `mysql`, 出现以下界面即登录成功
![][6]
## 新建数据库
CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
## 设置root账户密码
MySQL安装后root用户是没有密码的, 终端中执行以下命令可设置密码:
mysqladmin -u root password NEW_PASSWORD_HERE
NEW_PASSWORD_HERE为想要设置的密码, 比如: admin
# 修改mysql用户密码
mysql -u root -p
mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’); ```