1、保证ubuntu系统网络畅通
在虚拟机关机的状态下:设置->网络->连接方式->网络地址转换(NAT)。
2、更新数据源
sudo apt-get update
3、安装MySQL数据库
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
安装过程中需要设置root用户密码,检查是否安装成功
4、使用root登录,创建数据库、创建用户并授权
mysql -uroot -p123
mysql>create database testDB;
mysql>grant all privileges on testDB.* to test@"%" identified by '123456';
mysql>flush privileges;
5、用户登录、选择数据库、创建表、插入数据
mysql -utest -p123456 //按照前面的步骤,已经登录了,这一步无需操作,下一次登录需要
mysql>use testDB;
mysql>create table student(name char(20),sex char,age int,info varchar(100));
mysql>insert into student(name,sex,age,info) values("Steve",'m',18,"Apple");
mysql>select * from student;
mysql>commit;