zoukankan      html  css  js  c++  java
  • MySQL 5.7安装与配置

    Windows
    一、到MySQL官网下载压缩版本,下载后文件为mysql-5.7.20-winx64.zip,解压到D:developmysql-5.7.20-winx64。
     
    二、在系统变量Path末尾添上D:developmysql-5.7.20-winx64in。
     
    三、复制D:developmysql-5.7.20-winx64目录下my-default.ini(5.7.18以后发布包中没有这文件),改名为my.ini,my-default.ini内容如下:
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
    # *** default location during install, and will be replaced if you
    # *** upgrade to a newer version of MySQL.
    [mysqld]
    # 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
    # These are commonly set, remove the # and set as required.
    # basedir = .....
    # datadir = .....
    # port = .....
    # server_id = .....
    # 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
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
     
    四、修改my.ini,在[mysqld]下加入以下内容:
    #安装目录路径,所有的路径都是相对于这个的
    basedir =D:/develop/mysql-5.7.20-winx64
    #数据文件根目录
    datadir = D:/develop/mysql-5.7.20-winx64/data
    port = 3306
    character-set-server=utf8mb4
    collation-server=utf8mb4_bin
     
    五、以管理员身份启动命令行工具。
    cd D:developmysql-5.7.20-winx64in
    mysqld --install xx:将MySQL安装成windows的服务,xx是服务名,可以不指定
    mysqld --initialize:初始化数据库文件(为root生成随机密码,密码保存在datadir/计算机名.err文件)或者mysqld --initialize-insecure初始化(不会为root生成密码)。此时只允许root用户在localhost登录MySQL。
    mysqld --remove xx:卸载服务xx
     
    六、执行net start xx 启动服务,net stop xx停止服务。
     
    七、执行 mysql -u root -p登录,如果root用户使用随机密码登录的,那么在修改密码前输入sql语句比如use mysql就会出现错误:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement。此时可以使用 SET PASSWORD = PASSWORD('12345678') 修改密码后再操作。如果提示Your password does not satisfy the current policy requirements,是因为密码不够安全,执行set global validate_password_policy=0,再执行SET PASSWORD = PASSWORD('12345678') 。
     
    CentOS7
    一、到MySQL官网选择RHEL版本,下载 RPM Bundle文件,下载后文件名为 mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar。使用root用户安装。
     
    二、tar xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar,解压文件到当前目录,这个文件包含了以下rpm文件,不需要全部安装。
     
    三、在不清楚需要安装哪些rpm的情况下,可以按照以下方式测试。
    1.先尝试安装mysql-community-server,执行yum localinstall mysql-community-server-5.7.20-1.el7.x86_64.rpm,系统提示需要先安装 mysql-community-common和 mysql-community-client;
    2.执行yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm,系统提示和mariadb-libs-1:5.5.52-1.el7.x86_64冲突。
    3.执行yum remove mariadb-libs-1:5.5.52-1.el7.x86_64。
    4.执行yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm。
    5.执行yum localinstall mysql-community-client-5.7.20-1.el7.x86_64.rpm,系统提示需要先安装mysql-community-libs。
    6.执行yum localinstall mysql-community-libs-5.7.20-1.el7.x86_64.rpm。
    7.执行yum localinstall mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm。
    8.执行yum localinstall mysql-community-client-5.7.20-1.el7.x86_64.rpm。
    9.执行yum localinstall mysql-community-server-5.7.20-1.el7.x86_64.rpm
     
    四、
    系统配置:/etc/my.conf
    数据库目录:/var/lib/mysql/
    命令配置:/usr/share/mysql  (mysql.server命令及配置文件)
    相关命令:/usr/bin   (mysqladmin mysqldump等命令)
     
    五、
    1.MySQL配置文件位于/etc/my.cnf,打开它。修改my.cnf,在[mysqld]下加入以下内容:
    character-set-server=utf8mb4
    collation-server=utf8mb4_bin
    2.服务配置文件路径是/usr/lib/systemd/system/mysqld.service。安装好后,就可以启动MySQL了,执行systemctl start mysqld。systemctl status mysqld可以查看运行状态,systemclt enable mysqld设置为开机启动。系统会创建mysql用户组和mysql用户来管理MySQL服务。
    3.默认配置文件中log-error=/var/log/mysqld.log,它是MySQL的错误日志,在首次启动MySQL后,会随机生成root用户的密码并写入到里面,打开这个错误日志,找到下面这行,A temporary password is generated for root@localhost: Iz*0A1W1BouJ。Iz*0A1W1BouJ就是初始密码了。此时只允许root用户在localhost登录MySQL。
    4.执行 mysql -u root -p登录,如果root用户使用随机密码登录的,那么在修改密码前输入sql语句比如use mysql就会出现错误:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement。此时可以使用 SET PASSWORD = PASSWORD('12345678') 修改密码后再操作。如果提示Your password does not satisfy the current policy requirements,是因为密码不够安全,执行set global validate_password_policy=0,再执行SET PASSWORD for 'root'@'localhost' = PASSWORD('12345678') 。如果想关闭密码强度验证,可以在my.cnf里加入:validate-password=OFF。
    5.执行update mysql.user set Host='%' where user='root' and Host = 'localhost'和flush privileges,之后就可以远程访问MySQL。
  • 相关阅读:
    RS232引脚,RS485引脚
    求CRC16校验
    获得系统时间
    SVN 分支管理
    使用python和tableau对数据进行抓取及可视化
    使用python和tableau对数据进行抓取及可视化
    数据超市打造企业征信数据,引爆大数据风控
    数据超市打造企业征信数据,引爆大数据风控
    python用reduce和map把字符串转为数字的方法
    python用reduce和map把字符串转为数字的方法
  • 原文地址:https://www.cnblogs.com/gjb724332682/p/8610159.html
Copyright © 2011-2022 走看看