mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
官网: http://dev.mysql.com/downloads/mysql/
1
2
|
#rpm -qa|grep -i mysql
mysql-5.7.13-linux-glibc2.5-x86_64
|
*可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系:
1
|
#rpm -e mysql-5.7.13-linux-glibc2.5-x86_64
--nodeps
|
当然你的也可能不止这一个文件,也可能有多个,那么你就依次 rpm -e xx --nodeps 卸载,卸载完了再检查一下,若确定删除干净后,在经行下面步骤。
在这步之前一定要先确保你所建的用户以及用户组没有存在,要不然在后面的过程中会报错,删除时候要先删除用户在删除用户组名。
1
2
3
4
5
6
|
# userdel mysql # 删除用户
# groupdel mysql # 删除用户组名
# mkdir /home/mysql # 在home文件夹下创建文件夹mysql
# mkdir /home/mysql/data # 在mysql文件夹下创建文件夹data
# groupadd mysql # 创建一个名为mysql的用户组
# useradd -g mysql -d /home/mysql mysql # 在用户组下创建用户
|
1
2
3
|
# tar -xzvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz # 解压文件
# cd mysql-5.7.13-linux-glibc2.5-x86_64 # 进入
# mv * /home/mysql # 移动到之前我创建的mysql文件夹下。
|
1
2
3
4
5
6
7
8
|
# cd /home/mysql # 进入安装目录
# ./bin/mysql_install_db
--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
[WARNING] mysql_install_db
is
deprecated. Please consider switching
to
mysqld
--initialize 2015-11-10 02:09:23
[WARNING] The bootstrap log isn't empty: 2015-11-10 02:09:23
[WARNING] 2015-11-10T10:09:18.114182Z 0
[Warning]
--bootstrap is deprecated. Please consider using --initialize instead 2015-11-10T10:09:18.129343Z 0
[Warning] Changed limits: max_open_files: 1024 (requested 5000) 2015-11-10T10:09:18.129408Z 0
[Warning] Changed limits: table_open_cache: 431 (requested 2000)
|
mysql5.7新特性:由上面可以看出, mysql_install_db 已经不再推荐使用了,建议改成 mysqld --initialize 完成实例初始化。
1
2
3
4
5
|
# ./bin/mysqld
--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
# ./mysqld
--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
[Warning]
TIMESTAMP
with
implicit
DEFAULT
value
is
deprecated. Please use
--explicit_defaults_for_timestamp server option (see documentation for more details).
[ERROR]
--initialize specified but the data directory has files in it. Aborting. 2016-04-08T01:46:53.155879Z 0
[ERROR] Aborting
|
出现上面的错误是因为我们没有清空mysql的data目录, 执行清空命令如下:
1
2
3
4
5
6
7
8
9
|
# cd /home/mysql/data # 进入安装目录下的data目录
# rm -fr * # 清空数据
# cd /home/mysql
# ./bin/mysqld
--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
[Warning]
TIMESTAMP
with
implicit
DEFAULT
value
is
deprecated. Please use
--explicit_defaults_for_timestamp server option (see documentation for more details). 2016-04-08T01:47:59.945537Z 0
[Warning] InnoDB: New log files created, LSN=45790 2016-04-08T01:48:00.333528Z 0 [Warning] InnoDB: Creating
foreign
key
constraint
system tables. 2016-04-08T01:48:00.434908Z 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: ece26421-fd2b-11e5-a1e3-00163e001e5c. 2016-04-08T01:48:00.440125Z 0
[Warning] Gtid
table
is
not
ready
to
be used.
Table
'mysql.gtid_executed'
cannot be opened. 2016-04-08T01:48:00.440904Z 1
[Note] A
temporary
password
is
generated
for
root@localhost: **mjT,#x_5sW
|
牢记上面的随机密码, 如上**mjT,#x_5sW, 下面我们修改密码时需要用到。
1
2
3
|
# cd /home/mysql
# ./support-files/mysql.server start
Starting MySQL.. OK!
|
这是正常的情况下。 刚刚我用的是/home/mysql为mysql的安装目录basedir, 则在启动服务时会出现如下错误:
1
2
3
|
# ./support-files/mysql.server start
./support-files/mysql.server: line 276: cd: /usr/
local
/mysql:
No
such file
or
directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/
local
/mysql/bin/mysqld_safe)
|
由上面可知mysql的tar.gz安装包的默认安装目录为/usr/local/mysql, 这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径, 如下:
1
2
3
4
5
6
7
8
9
|
# vim support-files/mysql.server
--------------------------
...
basedir=/home/mysql
datadir=/home/mysql/data
...
--------------------------
# ./support-files/mysql.server
start Starting MySQL.. OK!
|
注意:上面 basedir 以及datadir部分是手动改的,那么在命令中如何手动改,步骤
1、 按 键盘 i 键(insert),然后就可以在你想要的位置编写了。 2、编辑完毕退出,esc键。 3、Shift键 加 :(冒号键)退出编辑。 4、wq! 保存编辑
1
|
# ln -s /home/mysql/bin/mysql /usr/bin/mysql
|
下面的前3步操作过程中,可能会出错,如果有错就跳过,因为不同电脑的环境不一样, 1、将默认生成的my.cnf备份
1
|
# mv /etc/my.cnf /etc/my.cnf.bak
|
如果这一步报错,没有关系,正常情况下是由于/ect文件夹下没有my.cnf锁引起的,创建一下就可以了,或者你不会创建 , 直接使用 vim /ect/my.cnf 命令编辑 , 然后直接退出编辑就可以,在执行这个命令就不会出错了,退出编辑命令 esc键 -> (shift键+ :(冒号键) -> wq! ),然后在执行上面的命令就不会报错了。 2、进入mysql的安装目录支持文件目录
1
|
# cd /home/mysql/support-files
|
3、拷贝配置文件模板为新的mysql配置文件,
1
|
# cp my-
default
.cnf /etc/my.cnf
|
4、设置编码,可按需修改新的配置文件选项, 不修改配置选项, mysql则按默认配置参数运行. 如下是我修改配置文件/etc/my.cnf, 设置编码为utf8以防乱码
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# vim /etc/my.cnf
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
character_set_server=utf8
init_connect=
'SET NAMES utf8'
[client]
default
-
character
-
set
=utf8
|
有的时候使用这个命令后,前3步有问题的这里可能my.cnf文件是空的,这个不要紧,既然没有生成,那么你就自己编辑喽!具体编辑怎么实现就参照步骤6.
1
2
3
4
5
|
# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld # 拷贝启动文件到/etc/init.d/下并重命令为mysqld
# chmod 755 /etc/init.d/mysqld # 增加执行权限
# chkconfig
--list mysqld # 检查自启动项列表中没有mysqld这个,
# chkconfig
--add mysqld # 如果没有就添加mysqld:
# chkconfig mysqld
on
# 用这个命令设置开机启动:
|
如果在执行第一步就报错,则说明刚刚在第8步中配置出问题了,那你就重新设置一下
做完这步后再重新执行下上面的操作 如果后面的操作中出现以下的问题
这样就是电脑环境的问题了,你就直接把
1
2
3
|
# service mysqld start # 启动服务
# service mysqld restart # 重启服务
# service mysqld stop # 停止服务
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# cd /home/mysql
# ./bin/mysqladmin -u root -p
'**mjT,#x_5sW'
password
'123456'
mysqladmin: # 刚刚之前的初始密码
[Warning] Using a
password
on
the command line interface can be insecure.
Warning: Since
password
will be sent
to
server
in
plain text, use ssl
connection
to
ensure
password
safety.
mysql> use mysql
Database
changed
mysql>
update
user
set
authentication_string =
PASSWORD
(
'123456'
)
where
user
=
'root'
;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.7.13,
for
linux-glibc2.5 (x86_64) using EditLine wrapper
Connection
id: 3
Current
database
: mysql
Current
user
: root@localhost
SSL:
Not
in
use
Current
pager: stdout
Using outfile:
''
Using delimiter: ;
Server version: 5.7.13 MySQL Community Server (GPL)
Protocol version: 10
Connection
: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 1
hour
29
min
17 sec
Threads: 1 Questions: 50 Slow queries: 0 Opens: 136 Flush tables: 1
Open
tables: 129 Queries per
second
avg
: 0.009
--------------
|
如果这一步完成不了的话,也就是修改不了密码的话,你也可以直接下面的方式先登录
但是如果不修改密码,不进每次登陆麻烦而且在执行一些操作会报一下错误
1
|
You must reset your
password
using
ALTER
USER
statement before executing this statement # 意思就是你必须重置你的密码在执行这个
execute
操作前
|
这里教大家用另外一种方式修改密码,这个是在已经登陆进去的情况下依次执行。
1
2
3
4
5
6
7
8
9
|
mysql>
SET
PASSWORD
=
PASSWORD
(
'123456'
); #
PASSWORD
()里面的123456 是我设置的新密码,你也可以设置成你的密码
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
mysql>
ALTER
USER
'root'
@
'localhost'
PASSWORD
EXPIRE NEVER;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
mysql> flush
privileges
;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@testfornss ~]# mysql -u root -p
Enter
password
:
Welcome
to
the MySQL monitor. Commands
end
with
;
or
\g.
Your MySQL
connection
id
is
4
Server version: 5.7.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle
and
/
or
its affiliates.
All
rights reserved.
Oracle
is
a registered trademark
of
Oracle Corporation
and
/
or
its
affiliates. Other names may be trademarks
of
their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear the
current
input statement.
mysql>
grant
all
privileges
on
*.*
to
'root'
@
'%'
identified
by
'123456'
;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
mysql>
|
或者:
1
|
grant
all
on
*.*
to
'root'
@
'%'
identified
by
'123456'
;
|
如果不设置远程连接,用mysql数据库连接工具可是连接不上的哦!!!
首先要知道,远程连接的Linux系统的ip,确保本机已经能够ping通的情况下再连接。
转载:http://www.cnblogs.com/gaojupeng/p/5727069.html