vim /etc/yum.repos.d/mariadb.repo
添加下面内容
[mariadb]
name=mariadb
baseurl=https://mirrors.ustc.edu.cn/mariadb/yum/10.10/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
[mariadb]
xx库的名称
name=库
baseurl=下载库的地址
gpgkey=密钥
gpgcheck=1开启校验
yum celan all # 清空缓存
yum makecache # 建立缓存
yum -y install mariadb-server mariadb-client
systemctl start mariadb # 启动
systemctl enable mariadb # 开机自启
yum -y instal net-tools # 安装net工具
netstat -ntlp | grep 3306
为了数据库的安全性和正常运行,初始化操作涉及
5
个步骤
1.设置root管理员在数据中的密码(默认为空,直接回车
)
2.设置root管理员在数据库中的专有密码
3.删除匿名用户
,使用root管理员远程登录数据库,确保安全性
4.删除默认的测试数据库
,取消测试数据库的全部访问权限
5.刷新
授权列联表,让初始化立即生效
mysql_secure_installation
Enter current password for root (enter for none): #初次运行直接回车设置密码
Switch to unix_socket authentication [Y/n] #输入y并回车
Change the root password? [Y/n] #输入y并回车
New password: #设置root用户密码
Re-enter new password: #再次输入密码
Remove anonymous users? [Y/n] #是否删除匿名用户,输入y回车
Disallow root login remotely? [Y/n] #是否禁止root远程登录,这里我们输入n
Remove test database and access to it? [Y/n] #是否删除test数据库,输入y回车
Reload privilege tables now? [Y/n] #是否重新加载表权限,输入y回车
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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the 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, 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] n
... skipping.
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!
mysql -uroot -p'刚才设置的密码'
show databases;
set password = PASSWORD(‘新密码’)
create database test;
use test;
create table mortal(id int,name char(32));
show tables;
desc motral;
\q
quit
exit
给motral
表增加两条数据
insert into mortal(id,name) values(1,"zero"),(2,"one");
查看id name
字段mortal表的数据
select id,name from mortal;
删除motral
表中id = 2
的数据
delete from mortal where id=2;
验证
select id,name from mortal;
更改id = 1
的字段name = yi
update mortal set name="yi" where id=1;
验证
select * from mortal;
grant 权限 on 数据库.表名 to 账户@主机名 #对特定数据库的特定表授权
grant 权限 on 数据库.* to 账户@主机名 #对特定数据库的所有表给予授权
grant 权限一,权限2,权限3 on *.* to 账户@主机名 #对所有数据库中的所有表给予多个权限
grant all privileges on *.* to 账户@主机名 #对所有数据库和表授权所有权限
zero
和密码zero
create user zero@’localhost’ identified by ‘zero’;
grant all privileges on *.* to username@’localhost’ identified by ‘password’;
grant create on test.* to zero@’localhost’ identified by ‘zero’;
mysql -uzero -pzero
grant create on *.* to one@’localhost’ identified by ‘one’;
drop user one;
flush privileges;
删除/tmp目录下所有内容
cd /tmp/
rm -rf *
mysqldump -uroot -p --all-databases > /tmp/db.dump
mysqldump -uroot -p test > /tmp/test.sql
进入数据库并删除数据库
drop database test;
show databases;
mysql -uroot -p < /tmp/db.dump
show databases;