1. #yum groupinstall mariadb mariadb-client -y

  2. #(yum install mariadb)上步直接安装mariadb,

  3. #systemctl start mariadb

  4. #mysql没有密码直接进入 安全启动用:mysqld_safe

  5. select user,password,host from user;

  6. 这里可以用

    update user set host='%' where user='root';

    替代:update user set host='%' where user='root' and host='localhost';

    如果报错:ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY',

    查看到

    host已经有了%这个值,所以直接运行命令: mysql>flush privileges;

  7. update user set password =PASSWORD('root') where user='root';

  8. 注意这样改了之后,本机启动的花mysql -uroot直接是匿名用户登陆,远程可以连接,但是本地登陆需要mysql -uroot -h127.0.0.1 -proot,不然进入后不能查看其他数据库,也没有权限。



下面是一些数据库的基本用法:

  1. 从文件里面load数据到table中

    >create database test1;

    >create table tb1(name varchar(20),number varchar(20));

    >load data local infile "/home/kevinsqb/桌面/score" into table tb1;

    表结构如下:

    +-------+------+
    | name  | age  |
    +-------+------+
    | alice |  100 |
    | bob   | 200  |
    +-------+------+
    /home/kevinsqb/桌面/score中的内容为:

    alice    100

    bob    200  (两组数据分两行,中间用"tab"隔开)

  2. 备份所有数据到一个文件中:

    mysqldump -uroot -proot -h127.0.0.1 --all-databases>all.sql

    还原的时候用:

    mysql -uroot -proot -h127.0.0.1<all.sql

    这样删除的数据库或者表,都能重建回来。简单测试通过,不知道是否有其他bug,欢迎大家一起探讨。


编码utf8

1、在[client]字段里加入default-character-set=utf8,如下:

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8

2、在[mysqld]字段里加入character-set-server=utf8,如下:

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8

3、在[mysql]字段里加入default-character-set=utf8,如下:

[mysql]
no-auto-rehash
default-character-set=utf8
使用SHOW VARIABLES LIKE ‘character%’;查看


新建与root权限相似用户:

  1. create user kevin@'%' identified by 'redhat';

  2. grant all privileges on *.* to kevin@%;(后面可以加with grant privilege来让他具有授权权限)

回收权限,用revoke,

想要查看某用户的权限,用 show grants for root@localhost