数据库
表的每一个列名字的头 叫做字段
是高级的exel表格软件
数据库种类
sqlserver sqllite db2
oracle > mysql 比较多
其中mysql 分支中有一个 mariadb
yum install mariadb-server -y
systemctl start mariadb
mysql_secure_installation
设定密码
mysql_secure_installation ##数据库安全初始化
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): ##数据库原始密码(默认没有直接回车)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] ##是否要设定数据库超级用户密码
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] ##是否删除匿名用户访问权限
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] ##是否禁止超级用户通过远程登陆
... 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] ##刷新数据库
- 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]
... 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!
mysql -uroot -p
登陆
去掉端口
netstat -antlupe |grep mysql
vim /etc/my.cnf.d
skip-networking=1
systemctl restart mariadb.service
就去掉了端口
数据库管理
mysql -uroot -p
> show databases; (不区分大小写)
> use mysql; 进去库 一定要用分号结尾
>show tables; 看到里面的东西
> select * from user 查看user库中的所有东西
> select Host,User,Password from user 选择字段查看部分内容
> create database westos; 建立库
mysql -uroot -p
show databases ;
use westos ;
create table linux (
-> username varchar(10) not null, 长度十个字节不能为空
-> password varchar(50) not null
-> );
这样就可以
desc linux; 查看表的结构
insert into linux values ('lee','123');
select * from linux 就可以看到了
这样就可以插入数据了
修改
alter table linux rename userdata ;
将表linux改名为 userdata
表中继续增加字段
alter table linux add age varchar(4);
默认在表中最后添加
alter table linux drop age;
删除 age
alter table linux add age varchar(4) after username ;
添加到 username 之后 不是最后一列
update linux set age='20' ;
都会改称 20岁
updpate linux set age='18' where username='lee' ;
updpate linux set age='22' where username='lee' and password='123';
增加限定条件地修改
删除数据库
delete from linux where username='westos';
从linux 中删除 westos
drop table linux ;
删除 表
drop database westos;
删除 库
用户授权
select User,Host from mysql.user;
create user lee@'%' 表示可以远程登陆
create user lee@localhost identified
mysql -ulee -plee 帐号密码登陆就可以测试了
show grants for lee@localhost; 查看权力
grant select on westos.* to lee@localhost;
可以允许查询westos库中的所有的表