zoukankan      html  css  js  c++  java
  • mysql(5.7)在CentOs7下的安装、配置与应用

    和之前版本的mysql有一些不同,现把完整过程记下来,或许对新手来说有用。

    本文描述的安装是采用通用的二进制压缩包(linux - Generic)以解压方式安装,相当于绿色安装了。
     
    一、下载通用安装二进制包
     
    先下载mysql安装包:打开 http://dev.mysql.com/downloads/mysql/
    选择 linux - Generic并在其下选择
    Linux - Generic (glibc 2.5) (x86, 64-bit), Compressed TAR Archive
    进行下载。可以先下载到一个临时目录里,解压后,得到两个包:
    mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 
    mysql-test-5.7.11-linux-glibc2.5-x86_64.tar.gz
    只需要mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 这个包就行了。
     
    二、建立用户和目录
     
    建立用户mysql,组mysql。后面mysql就使用这个用户来运行(注意这也是mysql启动脚本中默认的用户,因此最好不要改名)。
    #groupadd mysql
    #useradd -r -g mysql mysql
    (使用-r参数表示mysql用户是一个系统用户,不能登录)
     
    建立目录/work/program,后面mysql就安装在这个目录下面。
    #mkdir /work/program
     
     
    三、安装
     
    【解压】
    将前面得到的mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz解压至/work/program目录下
    #tar zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /work/program
     
    这时在program下得到的目录名很长,如果不想改名,则可以建立一个联接:
    #ln -s mysql-5.7.11-linux-glibc2.5-x86_64 mysql
    此后就可以用/work/program/mysql来找到mysql的安装目录了
     
    注意,如果mysql目录下没有data目录,手动建一个。
     
    【目录权限设置】
    将mysql及其下所有的目录所有者和组均设为mysql:
    #cd /work/program/mysql
    #chown mysql:mysql -R .
     
    【初始化】
    #/work/program/mysql/bin/mysqld --initialize --user=mysql --datadir=/work/program/mysql/data --basedir=/work/program/mysql
    注意:
    1. data目录解压后没有,需要手动建立(见上文);
    2. mysql5.7和之前版本不同,很多资料上都是这个命令
    ...../scripts/mysql_install_db --user=mysql
     而5.7版本根本没有这个。
     
    初始化成功后出现如下信息:
    201x-xx-xxT07:10:13.583130Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    201x-xx-xx T07:10:13.976219Z 0 [Warning] InnoDB: New log files created, LSN=45790
    201x-xx-xx T07:10:14.085666Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    201x-xx-xx T07:10:14.161899Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1fa941f9-effd-11e5-b67d-000c2958cdc8.
    201x-xx-xx T07:10:14.165534Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    201x-xx-xx T07:10:14.168555Z 1 [Note] A temporary password is generated for root@localhost: q1SLew5T_6K,
     
     
    注意最后一行,这也是和之有版本不同的地方,它给了root一个初始密码,后面要登录的时候要用到这个密码。
     
    【配置】
    将mysql/support-files下的my-default.cnf拷到安装目录的根目录下,改名为my.cnf
     
    [mysqld]
    basedir = /work/program/mysql
    datadir = /work/program/mysql/data
    port = 3306 
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    log-error=/work/program/mysql/logs
     
    四、运行
     
    【运行服务器程序】
    启动脚本如下:./mysqld_safe --defaults-file=/work/program/mysql/my.cnf --ledir=/work/program/mysql/bin --user=root  --skip-ssl
    由于mysqld_safe最终启动的是mysqlde,所以这里使用参数--ledir来指定mysqld的位置
     
     
    六、客户端连接测试
     
    #{mysql}/bin/mysql -uroot -p
    此时要求输入密码,就是前面初始化时生成的密码。
    这时如果连接服务的时候出现错误:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    则需要在在my.cnf中填加:
    [client]
    socket = /work/program/mysql/tmp/mysql.sock
     
    连上后,在做任何操作前,mysql要求要改掉root的密码后才能进行操作。
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> alter user 'root'@'localhost' identified by 'xxxxxxx';
     
     

    六、开启远程链接
    root 用户名 % 所有人都可以访问 ,password 密码

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
    FLUSH PRIVILEGES; 
     
     
     
     
     
  • 相关阅读:
    01视频传输,监控,直播方案摄像头如何采集的图像,MCU如何读取的图像数据
    203ESP32_SDK开发softAP+station共存模式
    2视频传输,监控,直播方案搭建视频流服务器,推送视频流,拉取视频流观看(RTMP,m3u8)
    F# (Part one)
    测试驱动开发(一)我们要的不仅仅是“质量”
    软件开发中的破窗效应
    结对编程神奇的力量
    《高性能网站建设指南》笔记
    【线程呓语】Thread
    【线程呓语】与线程相关的一些概念
  • 原文地址:https://www.cnblogs.com/qiumingcheng/p/7704525.html
Copyright © 2011-2022 走看看