mysql下载地址:http://dev.mysql.com/downloads/mysql/
二进制安装
1.添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。
①groupadd mysql
②useradd -r -g mysql mysql
* useradd -r参数表示mysql用户是系统用户,不可用于登录系统。
* useradd -g参数表示把mysql用户添加到mysql用户组中。
2.将二进制文件解压到指定的安装目录,我们这里指定为 /Ultrapower/test/,也可以是通用的/usr/local
①解压二进制文件, tar -zxvf /Ultrapower/test/mysql-5.7.13-linux-glibc2.5-i686.tar.gz
②mv mysql-5.7.13-linux-glibc2.5-i686 mysql 更改mysql目录名称
③cd mysql 进入mysql文件夹,也就是mysql所在的目录,
④更改mysql目录所属的组和用户。更改权限
chown -R mysql .
chgrp -R mysql .
3.初始化 MySQL 配置表
执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。
bin/mysql_install_db --user=mysql
报错:
2016-07-15 14:50:14 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-07-15 14:50:14 [ERROR] The data directory needs to be specified.
需要指定data目录,注意mysql服务进程mysqld运行时会访问data目录,所以必须由启动mysqld进程的用户(就是我们之前设置的mysql用户)执行这个脚本, 或者用root 执行,但是加上参数--user=mysql。
上文还有警告信息,说mysql_install_db 命令已经是弃用的,建议切换到mysqld --initialize命令
注:
mysql5.7和之前版本不同,很多资料上都是这个命令:../scripts/mysql_install_db --user=mysql,而mysql5.7的mysql_install_db命令是在bin目录下 的并且建议 用 mysqld --initialize命令
mysql5.7之前版本初始化配置表命令:
script/mysql_install_db --user=mysql --basedir=/Ultrapower/test/mysql --datadir=/Ultrapower/test/mysql/data/
--user 启动mysql的用户
--basedir mysql安装目录
--datadir mysql数据仓库目录
①初始化表配置正确执行步骤:
[root@rhel5-32 mysql]# mkdir data [root@rhel5-32 mysql]# bin/mysqld --initialize --user=mysql --basedir=/Ultrapower/test/mysql --datadir=/Ultrapower/test/mysql/data 2016-07-15T09:39:38.166396Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -explicit_defaults_for_timestamp server option (see documentation for more details). 2016-07-15T09:39:38.166941Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2016-07-15T09:39:38.166976Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 2016-07-15T09:39:39.486697Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-07-15T09:39:39.699652Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-07-15T09:39:39.767191Z 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: 0d154f38-4a70-11e6-8670-005056913e3a. 2016-07-15T09:39:39.771851Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql. gtid_executed' cannot be opened. 2016-07-15T09:39:39.773073Z 1 [Note] A temporary password is generated for root@localhost: i7YCy.:jv6yr
注意最后一行,这也是和之有版本不同的地方,它给了root一个初始密码,后面要登录的时候要用到这个密码。
②将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。
[root@rhel5-32 mysql]# chown -R root . [root@rhel5-32 mysql]# chown -R mysql data
③复制配置文件
[root@rhel5-32 mysql]# cp support-files/my-default.cnf /etc/my.cnf
④mysql5.7配置文件需要修改my.cnf关键配置, mysql5.7之前默认配置文件中是有配置项的,不用手动修改
[mysqld] basedir = /Ultrapower/test/mysql datadir = /Ultrapower/test/mysql/data port = 3306 socket = /Ultrapower/test/mysql/tmp/mysql.sock sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注意,tmp目录不存在,请创建之。否则会出错 创建后要赋予mysql权限,chown -R mysql:mysql tmp
如果mysql.sock指定到/tmp以外的目录,需要在my.cnf中添加[client]并且指定socket位置,
否则登录mysql时会报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
应该是,默认会找tmp目录下的sock文件
4. 将mysqld服务加入开机自启动项。
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务,
否则就只能使用{mysql}/bin/mysqld_safe &命令来启动服务
还需要把mysql.server中basedir的相关路径,改为自定义的路径,默认路径是/usr/local/mysql
#cp mysql.server /etc/init.d/mysql #chmod +x /etc/init.d/mysql
把mysql注册为开机启动的服务
#chkconfig --add mysql
查看是否添加成功
[root@rhel5-32 mysql]# chkconfig --list mysql mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
5.mysql服务的开启和关闭
#/etc/init.d/mysql start 或者 serivce mysql start 或者 bin/mysqld_safe& #/etc/init.d/mysql stop 或者 service mysql stop 或者 bin/mysqladmin -uroot -p
注:在bin/mysqld_safe&这个启动脚本里已默认设置--user=mysql;在脚本末尾加&表示设置此进程为后台进程,区别就是在控制台输入bg,即可将当前进 程转入后台, 当前shell 可进行其他操作。
bin/mysqladmin -uroot -p (注意此时的root是指mysql的root用户)
需要把mysqll加入到环境变量中,或者为mysql建立软链接
否则运行mysql命令会出现 -bash: mysql:command not found
不加环境变量,就要使用bin/mysql -uroot -p 或者bin/mysqladmin -uroot -p 命令来登录mysql服务
建立软链接:
ln -s /Ultrapower/test/mysql/bin/mysql /usr/local/bin
ln -s /Ultrapower/test/mysql/bin/mysqladmin /usr/local/bin
ln -s /Ultrapower/test/mysql/bin/mysqld_safe /usr/local/bin
6.加入环境变量
修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/Ultrapower/test/mysql:/Ultrapower/test/mysql/bin
export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。
7.登录mysql服务
执行:mysql -uroot -p生成的密码
连上后,在做任何操作前,mysql要求要改掉root的密码后才能进行操作。
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
需要执行:alter user 'root'@'localhost' identified by 'xxxxxxx';
mysql安装过程遇到的错误:
启动Mysql
bin/mysqld_safe --user=mysql &
[root@rhel5-32 mysql]# bin/mysqld_safe &
[1] 13863
[root@rhel5-32 mysql]# bin/mysqld_safe: line 541: /Ultrapowewr/test/mysql/data/mysqld_safe.pid: 没有那个文件或目录
awk: (FILENAME=- FNR=1) warning: error writing standard output (断开的管道)
2016-07-15T07:57:05.782967Z mysqld_safe Logging to '/Ultrapowewr/test/mysql/data/rhel5-32.err'.
touch: 无法触碰 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
chmod: 无法访问 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
touch: 无法触碰 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
chown: 无法访问 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
2016-07-15T07:57:05.877234Z mysqld_safe Starting mysqld daemon with databases from /Ultrapowewr/test/mysql/data
bin/mysqld_safe: line 135: /Ultrapowewr/test/mysql/data/rhel5-32.err: 没有那个文件或目录
bin/mysqld_safe: line 169: /Ultrapowewr/test/mysql/data/rhel5-32.err: 没有那个文件或目录
touch: 无法触碰 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
chown: 无法访问 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
chmod: 无法访问 “/Ultrapowewr/test/mysql/data/rhel5-32.err”: 没有那个文件或目录
2016-07-15T07:57:05.923131Z mysqld_safe mysqld from pid file /Ultrapowewr/test/mysql/data/rhel5-32.pid ended
bin/mysqld_safe: line 135: /Ultrapowewr/test/mysql/data/rhel5-32.err: 没有那个文件或目录
[root@rhel5-32 mysql]# service mysql restart
MySQL server PID file could not be found! [失败]
/etc/init.d/mysql: line 276: cd: /Ultrapowewr/test/mysql: 没有那个文件或目录
Starting MySQLCouldn't find MySQL server (/Ultrapowewr/test[失败]/bin/mysqld_safe)
这错误是因为,在/etc/my.cnf中配置basedir路径出错导致的
*************************************************************************************************************************************************
执行 mysql -uroot -p
出错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
查看 less data/rhel5-32.err
发现日志输出:
2016-07-15T08:13:31.786920Z 0 [Note] /Ultrapower/test/mysql/bin/mysqld: ready for connections.
Version: '5.7.13' socket: '/temp/mysql.sock' port: 3306 MySQL Community Server (GPL)
查看/etc/my.cnf中,socket配置:
# These are commonly set, remove the # and set as required.
basedir = /Ultrapower/test/mysql
datadir = /Ultrapower/test/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
socket文件目录为/temp/mysql.sock和错误提示不一样,
#由上可知my.cnf中定义的为/tmp目录下,而错误提示为/temp/mysql.sock/目录下
#也就是说mysqld已经声称了正确的sock文件,但客户端连接还是从初始目录去找sock文件
应该是因为,没有temp目录,mysql不会自动创建,找不到所致
*************************************************************************************************************************************************
错误:The server quit without updating PID file [失败]local/mysql/data/rhel5-32.pi
启动mysql服务时报如上错误,查看mysql日志发现
2016-07-26T02:07:28.134232Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2016-07-26T02:07:28.172866Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2016-07-26T02:07:28.172990Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2016-07-26T02:07:28.244892Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2016-07-26T02:07:28.252257Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2016-07-26T02:07:28.252344Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2016-07-26T02:07:28.253779Z 0 [Note] InnoDB: Waiting for purge to start 2016-07-26T02:07:28.305124Z 0 [Note] InnoDB: 5.7.13 started; log sequence number 2523957 2016-07-26T02:07:28.306232Z 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/mysql/data/ib_buffer_pool 2016-07-26T02:07:28.307231Z 0 [Note] Plugin 'FEDERATED' is disabled. 2016-07-26T02:07:28.315654Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2016-07-26T02:07:28.315736Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2016-07-26T02:07:28.315825Z 0 [Note] IPv6 is available. 2016-07-26T02:07:28.315860Z 0 [Note] - '::' resolves to '::'; 2016-07-26T02:07:28.316013Z 0 [Note] Server socket created on IP: '::'. 2016-07-26T02:07:28.316099Z 0 [ERROR] Could not create unix socket lock file /usr/local/mysql/tmp/mysql.sock.lock. 2016-07-26T02:07:28.316115Z 0 [ERROR] Unable to setup unix socket lock file. 2016-07-26T02:07:28.316128Z 0 [ERROR] Aborting
不能创建mysql.sock.lock文件,可能是tmp目录权限不足或者目录不存在的问题
执行 chown -R mysql:mysql tmp,然后启动mysql服务,启动成功
*************************************************************************************************************************************************
登录mysql,mysql -uroot -pi7YCy.:jv6yr
如出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),是因为不允许密码为空
如出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),可能密码错误
,终极办法停止mysql服务,删除data目录,重新初始化表数据,受权data目录给Mysql用户,用重新生成的临时密码登录。
转载自:http://blog.csdn.net/bao19901210/article/details/51917641