CentOS 6.8下二进制安装MySQL 5.6

来源:互联网 发布:js拼接json字符串数组 编辑:程序博客网 时间:2024/05/16 17:14

1.通过下面的命令查看环境中是否安装了mysql数据库,系统的只安装了mysql类库,没有安装mysql

[root@mysql001 opt]# rpm -qa | grep mysql
mysql-libs-5.1.73-7.el6.x86_64


2.mysql安装软件下载

国内的一些下载网络比较的麻烦,大家都懂的,大家可以通过下面的地址去下载。

http://mirrors.sohu.com/mysql/



3.查看Linux的版本信息

[root@mysql001 opt]# cat /etc/redhat-release
CentOS release 6.8 (Final)


4.mysql用户和组创建

[root@mysql001 opt]# groupadd mysql
[root@mysql001 opt]# useradd -g mysql mysql
[root@mysql001 opt]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@mysql001 opt]# 


5.将下载的安装包上传到/opt目录下面,解压

[root@mysql001 opt]# tar zxvf ./mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz


6.解压的文件夹创建软连接

[root@mysql001 opt]# ln -s /opt/mysql-5.6.34-linux-glibc2.5-x86_64 /opt/mysql


7.解压的文件夹的所有者改为mysql

[root@mysql001 opt]# chown -R mysql ./mysql

[root@mysql001 opt]# chown -R mysql ./mysql-5.6.34-linux-glibc2.5-x86_64


8.初始化mysql数据库

[root@mysql001 mysql]# scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data


9.拷贝mysql的启动文件

cp support-files/mysql.server /etc/init.d/mysqld

 修改文件中的内容

 basedir=/opt/mysql

 datadir=/opt/mysql/data


10.拷贝mysql配置文件

cp my.cnf /etc/my.cnf

 修改文件中的内容

 basedir = /opt/mysql
 datadir = /opt/mysql/data
 port = 3306
 server_id = 1


11.启动mysql服务

[root@mysql001 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 


12.改变mysql的密码

[root@mysql001 bin]# pwd
/opt/mysql/bin
[root@mysql001 bin]# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.34 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> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |
| root | mysql001  |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
|      | mysql001  |          |
+------+-----------+----------+
6 rows in set (0.01 sec)


mysql> update mysql.user set password=password('gaojian123') where user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


13.设置mysql能够进行远程连接

[root@mysql001 bin]# pwd
/opt/mysql/bin
[root@mysql001 bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.34 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> select host from user where  user='root';
+-----------+
| host      |
+-----------+
| 127.0.0.1 |
| ::1       |
| localhost |
| mysql001  |
+-----------+
4 rows in set (0.00 sec)


mysql> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> select host from user where user='root';
+-----------+
| host      |
+-----------+
| %         |
| 127.0.0.1 |
| ::1       |
| mysql001  |
+-----------+
4 rows in set (0.00 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

#修改host值(以通配符%的内容增加主机/IP地址,当然也可以直接增加某个特定IP地址,如果执行update语句时出现ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 错误,需要select host from user where user = 'root';

查看一下host是否已经有了%这个值,如果有了直接执行下面的flush privileges;即可)

14.为了方便使用mysql命令,添加环境变量

MYSQL_HONE=/opt/mysql

PATH=$MYSQL_HONE/bin:$PATH
export PATH


0 0
原创粉丝点击