1. 安装MySQL
sudo apt-get update sudo apt-get install mysql-server
2. 设置root账户密码
sudo mysql_secure_installation
3. 允许远程访问MySQL
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
找到下面这行,将它注释掉(在前面加上#):
# bind-address = 127.0.0.1
重新启动MySQL:
sudo service mysql restart
4. 创建新用户
mysql -u root -p CREATE USER 'newuser'@'%' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; exit;
5. 设置MySQL字符编码
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
在文件的结尾添加下面这行:
[mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
重新启动MySQL:
sudo service mysql restart
这些基本的MySQL服务器配置应该可以让你快速搭建一个可用的MySQL数据库。