[wpd@panda wpd]# sudo dnf install mysql-server
[wpd@panda wpd]# sudo systemctl start mariadb.service
[wpd@panda wpd]# sudo systemctl enable mariadb.service
[wpd@panda wpd]# mysql_secure_installation
In order to log into MariaDB to secure it, we'll need the current
password for the wpd user. If you've just installed MariaDB, and
you haven't set the wpd password yet, the password will be blank,
so you should just press enter here.
Enter current password for wpd (enter for none): (初次安装没有密码直接Enter)
Setting the wpd password ensures that nobody can log into the MariaDB
wpd user without the proper authorisation.
Set root password? [Y/n] Y
New password: (输入密码)
Re-enter new password: (输入密码)
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, wpd should only be allowed to connect from 'panda'. This
ensures that someone cannot guess at the wpd password from the network.
Disallow wpd login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
------------------------------------安装完毕----------------------------------------
[wpd@panda wpd]# mysql -u root –h 127.0.0.1 –p
//链接本机的数据库
MariaDB [(none)]> show databases;
//查看所有数据库
MariaDB [(none)]> create database test;
//创建数据库test
MariaDB [(none)]> drop database test;
//删除数据库test
MariaDB [(none)]> use test;
//使用数据库test
MariaDB [(none)]> exit;
//退出数据库
MariaDB [(none)]> create table test(
学号 int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
姓名 varchar(30) NOT NULL DEFAULT '' COMMENT 'name',
班级 tinyint(3) unsigned NOT NULL,
性别 enum('男','女','保密') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '保密' COMMENT 'sex',
入学时间 int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (学号)
)ENGINE=InnoDB COMMENT = '学生表';
MariaDB [test]> drop table test; 删除表
MariaDB [(none)]> rename table study to test ;
MariaDB [test]> show columns from test; //显示字段(表头)
MariaDB[test]> insert into test (学号,姓名,班级,性别,入学时间) values (1001,"wangpandong",3," 男",20090901); //添加内容
MariaDB[test]> select * from test; //查看表test中的内容
MariaDB [test]> select * from test where 姓名 = "wangpandong";
MariaDB [test]> select * from test where 姓名 = "wangpandong" and 学号 = 1001;
MariaDB[test]> select 班级 from test where 姓名 = "wangpandong" and 学号 = 1001;
MariaDB [test]> select 班级 , 性别 from test where 姓名 = "wangpandong" and 学号 = 1001;
MariaDB [test]> update test set username= "zhangsanfeng" where id = 1001;
MariaDB [test]> delete from test where id = 1001;
-------------------------------------创建一个学生表并实现增删改查---------------------------