1. 从官网下载 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
经测试, 本文还适用于如下版本:
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/
2.检查你所用的Linux下有没有安装过mysql,没有卸载干净
#rpm -qa|grep -i mysql
mysql-5.7.13-linux-glibc2.5-x86_64
3. 创建mysql的用户组/用户, data目录及其用户目录
# 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 # 在用户组下创建用户
4、解压安装包并将解压包里的内容拷贝到mysql的安装目录/home/mysql
# 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文件夹下
# cd /home/mysql
# ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
牢记上面的随机密码, 如上**mjT,#x_5sW, 下面我们修改密码时需要用到。
6、检测下是否能启动mysql服务
# cd /home/mysql
# ./support-files/mysql.server start
Starting MySQL.. OK!
# 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! 保存编辑
# ln -s /home/mysql/bin/mysql /usr/bin/mysql
# mv /etc/my.cnf /etc/my.cnf.bak
cd /home/mysql/support-files
# cp my-default.cnf /etc/my.cnf
# 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
mysql服务的启动/重启/停止
# service mysqld start # 启动服务
# service mysqld restart # 重启服务
# service mysqld stop
# 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
--------------
这里教大家用另外一种方式修改密码,这个是在已经登陆进去的情况下依次执行。
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
12. mysql远程授权
[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>
http://blog.csdn.net/cz596738622/article/details/53434790
本文转自 知止内明 51CTO博客,原文链接:http://blog.51cto.com/357712148/1961869,如需转载请自行联系原作者