• centos7下安装mysql5.7


    1.官网找到 https://dev.mysql.com/downloads/repo/yum/

    2.wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

    rpm -ivh mysql80-community-release-el7-3.noarch.rpm

    若果报错误:warning: mysql80-community-release-el8-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

    解决:rpm --import /etc/pki/rpm-gpg/RPM*

    重新  rpm -ivh mysql80-community-release-el7-3.noarch.rpm

    说明:虽然下载的源文件名字为mysql80-community-release-el7-3.noarch.rpm,不用担心,里边其实是包含了我们所要装的版本

    yum repolist all | grep mysql 

    可以看到,默认的安装源为mysql80-community版本

    配置默认源5.7

    使用yum-config-manager --disable mysql80-community来取消mysql80-community的默认安装,然后

    使用yum-config-manager --enable mysql57-community来使能mysql57-community成为yum默认安装版本。

    安装

    执行安装命令:

    yum install mysql-community-server

    yum -y install mysql-devel

    启动mysql服务

    systemctl restart mysqld.service //重启mysql服务

    systemctl status mysqld.service //查看mysql状态

    systemctl stop mysqld.service //停止mysql服务
    ————————————————

    获取临时密码

    临时密码存在/var/log/mysqld.log中,使用如下命令查看:

    grep "temporary password" /var/log/mysqld.log

    登陆mysql

    mysql -u root -p

    Enter password:

    进入mysql > update user set authentication_string = password('root') where user='root'; 后面跟分号 密码策略:大小写字母+数字+特殊符号

    也可忽略验证:

    vim /etc/my.cnf

    增加 

    skip-grant-tables 忽略验证  保存,重新运行mysql  mysql -u root -p  直接enter 进入不用输入密码 
    修改用户密码:
    update user set authentication_string = password('root') where user='root'; 
    root 登录后
    一定要修改密码

          alter user 'root'@'localhost' identified by 'test';

    然后就可以了。


    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #skip-grant-tables
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/data/mysql
    #socket=/var/lib/mysql/mysql.sock
    socket=/data/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

    更改用户权限增加用户

    1.创建新用户的SQL语句:

    CREATE USER ‘pig‘@‘192.168.1.101_‘ IDENDIFIED BY ‘123456‘;

    // pig 是用户名,@后面的是指定ip(如果不限制只能在某个ip,@后面改为‘%’),by后面的是 密码

    2.设置这个用户的权限,使用GRANT语句

    (如限制某个用户只能查询,不能修改,或者限定只能查询特定的表)

    语法:

    mysql> grant 权限1,权限2,...权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令‘;

    可选的权限列表:select, insert, update, delete, create, drop,

    index, alter, grant, references, reload,

    shutdown, process, file等14个权限

    eg:

    1. mysql> grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123‘;

    给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表

    进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

    2. mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123‘;

    给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。

    3. mysql>grant all privileges on *.* to joe@10.163.225.87 identified by ‘123‘;

    给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

    4. mysql>grant all privileges on *.* to joe@localhost identified by ‘123‘;

    给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

    5. mysql>flush privileges; //刷新系统权限表

    use mysql  

    show databases;(显示db)

    show tables;显示表

    describe test; 或者show columns from test;显示表结构

    drop table test;删除表

    create table test( id int not null auto_increment primary key, title varchar(100) not null, name varchar(50) not null, age int not null, createtime datetime not null); 创建表

    insert into test(title,name,age,createtime) values ('11','222',11,'2021-09-09'); 添加数据

    update test set title='876868' where id =1;  修改数据

    delete from test where id=1;  删除数据

    select * from test order by id asc; 排序

  • 相关阅读:
    有趣的网站
    Python-Day2
    C# EF增删改查
    LINQ教程
    命名空间“System.Web”中不存在类型或命名空间名称“Optimization”(是否缺少程序集引用?)
    Log4Net组件的应用详解
    log4net应用
    Select count(*)和Count(1)的区别和执行方式
    Ms sql 2005 中的bit 数据类型
    关于CLR、CIL、CTS、CLS、CLI、BCL和FCL
  • 原文地址:https://www.cnblogs.com/elsons/p/15234070.html
Copyright © 2020-2023  润新知