Laravel 部署:Ubuntu 安装 MySQL
环境
- Ubuntu 18.04 LTS
以下请选择您所需要的 MySQL 版本。
安装 MySQL 5.7
-
首先运行下面三条命令,进行常规安装
sudo apt update # 更新源 sudo apt-get install mysql-server mysql-client # 安装 MySQL 的服务端和客户端 sudo apt install libmysqlclient-dev # 安装所需依赖 sudo netstat -tap | grep mysql # 检查状态
-
初始化配置
sudo mysql_secure_installation # 里面选项较多,在这里可以设置 root 密码、删除测试数据库、禁止远程访问(即只能本地访问或者 via SSH:通过 SSH 访问)等等。
配置项如下:
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的选项) #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them... Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项) #4 Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network... Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项) #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项) #6 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
-
配置远程访问(可选,如果上个步骤您关闭了 root 账户的远程链接,那么有需要的时候,可以如下操作)
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf # 该命令是打开mysql的配置文件,我们需要注释掉bind-address = 127.0.0.1 #保存并退出后登陆mysql服务 mysql -uroot -p mysql> grant all on *.* to root@'%' identified by '请设置 root 密码' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
-
最后,退出并重启mysql服务就好了
安装 MySQL 8.0
wget -c https://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb # 下载 MySQL 8.0 的 deb 包
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb # 安装 deb 包
sudo apt update
sudo apt-get install -y mysql-server mysql-client
sudo mysql_secure_installation