mysql:
1.
登陆(关闭端口,设置密码)
     yum clean all
     yum install mariadb-server -y     ##
安装数据库
linux运维-mysql
     systemctl start mariadb           ##启动数据库

     mysql                             ##进入数据库
     netstat -antlpe | grep mysql      ##查看mysql所占用的端口
linux运维-mysql
     vim /etc/my.cnf                   ##编辑mysql配置文件,添加:skip-networking=1 (跳过网络链接)

linux运维-mysql
     systemctl restart mariadb         ##重启服务

     netstat -antlpe | grep mysql      ##再次查询mysql所占端口,跳过网络链接之后,查询不到端口
linux运维-mysql
     mysql_secure_installation         ##给数据库添加密码,并且设置匿名用户无法登陆(全选yes)

linux运维-mysql


linux运维-mysql     mysql                             ##匿名用户登录失败
     mysql -uroot -p                   ##用户输入密码登陆成功 -u代表用户 -p代表密码
linux运维-mysql

2.查询:(命令后面必须加;不然命令不执行)

    show databases;    ##显示数据库
linux运维-mysql
    use mysql;         ##进入mysql库

    show tables;       ##显示当前库中表的名称
linux运维-mysql
    select * from user;    ##查询user表中的所有内容(*可以用此表中的的任何字段来代替)

linux运维-mysql



linux运维-mysql   

desc user;     ##查询user表的结构(显示所有字段的名称)
linux运维-mysql

3.数据库及表的建立

    createdatabase westos;  ##创建westos库(创建的库以文件的形式存在/var/lib/mysql中)
linux运维-mysql

linux运维-mysql   

MariaDB [westos]> create tablelinux(                ##创建linux表格,varchar格式下最多有255个字节
            -> username varchar(15) notnull,    ##varchar(M)M表示该数据类型所允许保存的字符串的最大长度,varchar所支持的最大长度255
            -> password varchar(15) notnull );
linux运维-mysql
        select * from linux;   ##查询新建表中内容

linux运维-mysql
        insert into linux values('user1','123');             ##向linux表中插入数据,username字段的数据为user1,password字段的数据为
123
linux运维-mysql
        select * from linux;
 
linux运维-mysql
    insert into linux values('user2',password('123') );  ##插入的password的字段的数据是用password加密过的

linux运维-mysql
    select * from linux ;

linux运维-mysql

4.更新数据库信息

    update linux set password='abc' whereusername='user1';         ##更新user1的密码
        select * from linux
linux运维-mysql
    update linux setpassword=password('abc') where username='user12';    ##更新user12密码并且加密

        select * from linux
linux运维-mysql
    update linux setpassword=password('abc') where  username='user1'or username='user2';  ##更新user1和user2密码

        select * from linux
linux运维-mysql
    delete from linux whereusername='user1';                ##删除user1信息

    select * from linux
linux运维-mysql
    alter table linux add age varchar(20)not null;                      ##更改表格结构添加一列age到linux最后一列

    select * from linux
linux运维-mysql
    alter table linux add date varchar(20)not null after password;      ##更改表格结构添加一列date在password之后

    select * from linux
linux运维-mysql  
    alter table linux drop age    
##更改表格结构删除age一列
linux运维-mysql
5.
数据库的备份
    mysqldump -uroot -p --all-database          ##备份所有表中的所有数据
linux运维-mysql
    mysqldump -uroot -p --all-database--no-data        ##备份所有表,但不备份数据

linux运维-mysql
    mysqldump -uroot -p westos              ##备份westos表

linux运维-mysql
    mysqldump -uroot -p westos >/mnt/westos.sql        ##备份westos表并保存到/mnt/westos.sql中

    mysqldump -uroot -p westos linux >/mnt/linux.sql   ##备份westos数据库中的linux表到/mnt/linux.sql中
linux运维-mysql

6.删除数据库

    delete from linux whereusername='user1';           ##删除linux表中user1的所有信息
linux运维-mysql
    drop table linux;              ##删除linux表

linux运维-mysql
    drop database westos;                      ##删除westos数据库

linux运维-mysql

7.数据库的恢复

    mysql -uroot -predhat -e "createdatabase westos;"      ##恢复之前建立westos数据库
linux运维-mysql
    mysql -uroot -predhat westos </mnt/westos.sql          ##恢复westos数据库

linux运维-mysql
    mysql -uroot -predhat westos linux< /mnt/linux.sql     ##恢复linxu表内容

linux运维-mysql

8.用户授权

    create user [email protected] by 'redhat';        ##创建redhat用户,密码为redhat,只能本机登陆
    create user [email protected]'%' identified by'redhat';          ##创建redhat用户,密码为redhat,可以通过网络访问
linux运维-mysql
    grant insert,update,delete,select onwestos.linux to [email protected];  ##给[email protected]授权(插入,更新,删除)

linux运维-mysql
    grant select on westos.* [email protected]'%';
linux运维-mysql
    show grants for [email protected]'%';                 ##显示[email protected]'%'权限

linux运维-mysql
    show grants [email protected];
linux运维-mysql              
    revoke delete on westos.linux [email protected];        ##去除[email protected]的delete权限

linux运维-mysql
    drop user [email protected]'%';                       ##删除用户

linux运维-mysql

9.密码修改

    已知密码修改密码   
    mysqladmin -uroot -pwestos passwordabc             ##修改超级用户密码

linux运维-mysql
    密码忘记修改密码

    systemctl stop mariadb                 
    mysql_safe --skip-grant-tables &                ##
开启mysql登陆接口并忽略授权表
    mysql                               ##mysql可以直接登陆
    update mysql.user setPassword=password('abc') where User='root';   ##修改root密码
    ps aux | grep mysql                     ##过滤mysql所有进程
    kill -9 mysqlpid                            ##结束mysql的所有进程
    systemctl start mariadb                     ##重启mysql
    mysql -uroot -pabc                      ##使用新密码登陆测试

linux运维-mysql

linux运维-mysql



linux运维-mysql   

#########################图形界面管理数据库####################################
创建实验环境:

    yum install httpd php php-mysql-y               ##安装httpd(是Apache超文本传输协议HTTP服务器的主程序),php(超文本预处理器,是一种通用的开源脚本语
                               言),php-mysql(通过php连接2和操作数据);
linux运维-mysql


linux运维-mysql    systemctl start httpd
    systemctl stop firewalld
    systemctl disable firewalld
    systemctl enable httpd
2.下载
    phpMyAdmin-xxx-all-languages.tar.br2                              ##xxx为版本
    tar jxfphpMyAdmin-xxx-all-languages.tar.br2 -C /var/www/html    ##将phpMyAdmin-xxx-all-languages.tar.br2解压到/var/www/html下
    cd /var/www/html                                         
    mkdir mysqladmin                     ##
新建mysqladmin目录
    mv phpMyAdmin-xxx-all-languagesmysqladmin               ##将解压后的phpMyAdmin-xxx-all-languages移动到mysqladmin目录下
    cd mysqladmin
        cd  phpMyAdmin-xxx-all-languages
    ls
    cp -p config.sample.inc.phpconfig.inc.php               ##
复制config.sample.inc.php文件
    vim config.inc.php                                       ##编辑config.inc.php文件内容
        $cfg['blowfish_secret'] = 'mysql';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */   
    systemctl restart httpd
linux运维-mysql


linux运维-mysql
linux运维-mysql

3.测试:
    访问:http://172.25.254.122/mysqladmin
linux运维-mysql

相关文章:

  • 2021-07-23
  • 2021-12-13
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2021-12-06
猜你喜欢
  • 2021-11-29
  • 2021-12-06
  • 2021-12-06
  • 2022-01-18
  • 2021-12-06
  • 2021-12-06
相关资源
相似解决方案