sudo apt install mysql-server
#sudo mysql_secure_installation
sudo systemctl status mysql.service
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
#屏蔽bind相关行,允许远程访问。
sudo systemctl restart mysql
sudo mysql -uroot -p
回车
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Cindigo@2023';
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'Cindigo@2023';
Query OK, 0 rows affected (0.07 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
create table people(
id INT AUTO_INCREMENT PRIMARY KEY,
name varchar (20) not null,
gender varchar(20) not null,
age INT not null,
comments varchar(100)
);
INSERT INTO people (name, gender, age, comments) VALUES ('张三', '男', 10, '调皮');
INSERT INTO people (name, gender, age, comments) VALUES ('李四', '女', 55, '售票员');
INSERT INTO people (name, gender, age, comments) VALUES ('王五', '男', 35, '灌篮高手');
flush privileges;
SELECT * FROM students;