和之前版本的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,拷到/etc下(或者考到{mysql}下,然后作一个软链接到/etc下):
#cp /work/program/mysql/support-files/my-default.cnf /etc/my.cnf
my.cnf中关键配置:
[mysqld]
basedir = /work/program/mysql
datadir = /work/program/mysql/data
port = 3306
socket = /work/program/mysql/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注意,tmp目录不存在,请创建之。
如果不把my.cnf拷到/etc下,运行时会出现:
mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)
这样的出错提示,说明它没找到my.cnf中的配置;而去找了程序编译时的默认安装位置:/usr/local/mysql
四、运行
【运行服务器程序】
#{mysql}/bin/mysqld_safe&
注:在这个启动脚本里已默认设置--user=mysql;在脚本末尾加&表示设置此进程为后台进程,区别就是在控制台输入bg,即可将当前进程转入后台,当前shell可进行其他操作。
【停止mysql】
{mysql}/bin/mysqladmin -uroot -p
(注意此时的root是指mysql的root用户)
五、设置mysql以服务运行并且开机启动
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限
#cp mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
把mysql注册为开机启动的服务
#chkconfig --add mysql
当然也可以手动进行服务的开启和关闭:
#/etc/init.d/mysql start
#/etc/init.d/mysql stop
六、客户端连接测试
#{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';
七、TIPS
【查看mysql是否运行】
ps -ef|grep mysqld
netstat -lnp | grep -i mysql
【mysql启动时读取配置文件my.cnf的顺序】
可以运行如下命令查看:
./bin/mysqld --verbose --help |more
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
可以看到,启动时可以从上述目录下读取配置文件my.cnf。如果当前my.cnf文件不位于上述位置,则必须考过去或做链接。
【end】
- centOS7下Spark安装配置
环境说明: 操作系统: centos7 64位 3台 centos7-1 192.168.190.130 master centos7-2 192.168.190.129 slave1 centos7 ...
- Centos7下yum安装配置nginx与php
实现LNMP环境搭建. 开始安装Nginx和PHP-FPM之前,首先卸载系统中以前安装的Apache和PHP保证安装不会冲突.用root登录输入下面的命令: yum remve httpd* php* ...
- centos7下elasticSearch安装配置
OS:Centos7x虚拟机 1H2Gjdk:1.8elasticsearch:5.6.0 1.下载“elasticsearch-5.6.0.tar.gz”解压到/usr/local/elastics ...
- 在Centos7下源代码安装配置Nginx
1.安装前准备开发环境安装pcre开发包:yum install -y pcre-devel 安装编译源码所需的工具和库:yum install gcc gcc-c++ ncurses-devel p ...
- centos7下zookeeper安装配置
1.下载zookeeper文件 cd /opt/ wget http://mirrors.hust.edu.cn/apache/zookeeper/stable/zookeeper-3.4.9.tar ...
- Linux(CentOS7)下rpm安装MySQL8.0.16
记录一下自己在 CentOS7 下 rpm 安装 MySQL8.0.16 的过程. 一.准备工作 1. 下载MySQL所需要的安装包 从 MySQL官网 下载,上传至 CentOS 系统 /usr/l ...
- Linux(CentOS7)下二进制安装MySQL5.7.26
记录一下自己在 CentOS7 下二进制安装 MySQL5.7.26 的过程,之前使用 Linux(CentOS7)下rpm安装MySQL8.0.16 之后发现 rpm 方式安装不利于维护,也不利于单 ...
- EnvironmentError: mysql_config not found问题解决(centos7下python安装mysql-python)
centos7下python安装mysql-python模块,执行命令: pip install mysql-python 出现报错:EnvironmentError: mysql_config no ...
- centos7下编译安装php-7.0.15(PHP-FPM)
centos7下编译安装php-7.0.15(PHP-FPM) 一.下载php7源码包 http://php.net/downloads.php 如:php-7.0.15.tar.gz 二.安装所需依 ...
- Centos7下快速安装Mongo3.2
Centos7下快速安装Mongo3.2 一般安装Mongo推荐源码安装,有时候为了快部署测试环境,或者仅仅是想装个mongo shell,这时候yum安装是最合适的方式, 下面介绍一下如何在Cent ...
随机推荐
- Python模块学习笔记— —time与datatime
Python提供了多个内置模块用于操作日期时间.像calendar,time,datetime.首先对time模块中最经常使用的几个函数作一个介绍,它提供的接口与C标准库time.h基本一致.然后再介 ...
- last与lastlog命令
lastlog 列出所有用户最后登录的时间和登录终端的地址,如果此用户从来没有登录,则显示:**Never logged in**last 列出用户所有的登录时间和登录终端的地址
- 线程:CountDownLatch同步工具
一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 类似计数器,当计数器的值为0时,继续往下执行. package ch03; import java.util.R ...
- SQL常用分页
top式 string sqltext = string.Format(" SELECT TOP {0} * FROM '表' WHERE ('字段' NOT IN (SELECT TOP ...
- 阻止IOS自动识别页面上的电话号码、email地址
之前写页面的时候碰到一个很恶心的情况,在6P上数字自动变色,后来找了一些资料: 在iOS的浏览器上,他们有时候会有一些“自作聪明”,自动把页面上的一串数字识别成电话号码,这样用户不小心点击这串数字,就 ...
- ASP.NET MVC:自定义 Route 生成小写 Url(转)
先给出本文中测试用的 controller: public class PersonsController : Controller { public ActionResult Query(strin ...
- js Range
http://www.zhangxinxu.com/wordpress/2011/04/js-range-html%E6%96%87%E6%A1%A3%E6%96%87%E5%AD%97%E5%86% ...
- UIView的动画之初步学习
animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIView ...
- automaticallyAdjustsScrollViewInsets的作用
简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview ...
- Mybatis Generator最完整配置详解
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...