栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux(centos7)下mysql(rpm包)安装配置

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux(centos7)下mysql(rpm包)安装配置

软件包准备

百度网盘:链接:https://pan.baidu.com/s/1h7kyhiBwlPKyRaTJtmop3Q 
提取码:0601

阿里云  链接:https://www.aliyundrive.com/s/3BqiZmsfUJX

[root@zabbix software]# ll
总用量 206280
-rw-r--r--. 1 root root  26597364 11月 30 20:31 mysql-community-client-5.7.34-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    317444 11月 30 20:31 mysql-community-common-5.7.34-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   2472844 11月 30 20:34 mysql-community-libs-5.7.34-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 181833876 11月 30 20:28 mysql-community-server-5.7.34-1.el7.x86_64.rpm
  1. 安装前我们先检查之前是否安装过mysql,如果有安装,卸载掉
    [root@zabbix software]# rpm -qa | grep mariadb #查看是否已经安装自带的mysql(mariadb)
    mariadb-libs-5.5.56-2.el7.x86_64
    [root@zabbix software]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 #强制卸载
    
  2.  安装mysql  注意   执行顺序不能互换
    [root@zabbix software]# rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
    [root@zabbix software]# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
    [root@zabbix software]# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
    [root@zabbix software]# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm

         将mysqld复制到init.d目录

[root@zabbix system]# cp /usr/sbin/mysqld /etc/init.d/

        设置mysql服务开机自启->启动服务->查看状态 

[root@zabbix system]# systemctl enable mysqld
[root@zabbix system]# systemctl start mysqld
[root@zabbix system]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2021-11-30 21:10:30 CST; 29s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2909 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 2858 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2912 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2912 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

11月 30 21:10:28 zabbix systemd[1]: Starting MySQL Server...
11月 30 21:10:30 zabbix systemd[1]: Started MySQL Server.

        查看mysql临时密码 并登录修改root密码 

#查看临时密码
[root@zabbix ~]# cat /var/log/mysqld.log |grep 'temporary password'
2021-11-30T13:10:28.998583Z 1 [Note] A temporary password is generated for root@localhost: *zk3wwicT#Fa

#使用临时密码登录数据库
[root@zabbix ~]# mysql -uroot -p*zk3wwicT#Fa
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> 

#在mysql5.6以后,当我们设置弱密码时会报错
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    

        怎么办呢?

方案一:设强类型密码 这里就不做介绍 比如女朋友生日 不过要记得是哪个女朋友的生日噢

方案二:修改策略

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

这时候就可以设置弱类型密码了

mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

授予root用户远程访问权限 并刷新使其生效

mysql> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

远程连接的时候记得关防火墙

[root@zabbix ~]# systemctl stop firewalld

介绍一些MySQL的常见命令

1.查看当前所有的数据库

show databases;

2.使用/打开指定数据库

use 库名;

3.查看当前库的所有表

show tables;

4.查看其它库的所有表

show tables from 库名;

5.创建表

create table 表名(

列名 列类型,

列名 列类型,

。。。

);

6.查看表结构

desc 表名;

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/618239.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号