Step 1:安装MySQL
sudo apt-get update
sudo apt-get install mysql-server
Step 2:登录MySQL
mysql -u root -p
Enter password:
Step 3:创建新用户
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Step 4:授予权限
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
Step 5:刷新权限
FLUSH PRIVILEGES;
Step 6:编辑配置文件
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address
改为0.0.0.0
,以允许远程访问。
bind-address = 0.0.0.0
Step 7:重启MySQL
sudo service mysql restart
至此,MySQL数据库已经配置完成。如果您需要在远程主机上访问MySQL,请使用以下命令:
mysql -u newuser -h your_server_ip -p