CentOS 6.7 下RPM方式安装MySQL 5.6

1. 下载Linux对应的RPM包,如:CentOS6.7_64对应的RPM包,如下:

[root@mysql ~]# ll
总用量 113808
-rw——-. 1 root root    1434 12月 13 18:47 anaconda-ks.cfg
-rw-r–r–. 1 root root    42556 12月 13 18:47 install.log
-rw-r–r–. 1 root root    10033 12月 13 18:45 install.log.syslog
-rw-r–r–. 1 root root 23135399 12月 13 18:56 MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm
-rw-r–r–. 1 root root  4586217 12月 13 18:56 MySQL-devel-5.6.25-1.linux_glibc2.5.x86_64.rpm
-rw-r–r–. 1 root root 88715219 12月 13 18:56 MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm

2. 检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
[root@mysql ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-5.el6_6.x86_64
[root@mysql ~]# rpm -ev mysql-libs-5.1.73-5.el6_6.x86_64 –nodeps

3. 安装MySQL
[root@mysql ~]# rpm -ivh MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing…                ########################################### [100%]
  1:MySQL-server          ########################################### [100%]
warning: user mysql does not exist – using root
warning: group mysql does not exist – using root
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
[root@mysql ~]# rpm -ivh MySQL-devel-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing…                ########################################### [100%]
  1:MySQL-devel            ########################################### [100%]
[root@mysql ~]# rpm -ivh MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing…                ########################################### [100%]
  1:MySQL-client          ########################################### [100%]

4. 初始化MySQL及设置密码
[root@mysql ~]# /usr/bin/mysql_install_db            — mysql_install_db脚本来生成帐户和相应权限许可表
WARNING: The host ‘mysql’ could not be looked up with /usr/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
。。省略输出。。
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
–defaults-file argument to mysqld_safe when starting the server
[root@mysql ~]# service mysql start
Starting MySQL. SUCCESS!
[root@mysql ~]# cat /root/.mysql_secret    –查看root账号密码
# The random password set for the root user at Tue Dec 13 18:59:06 2016 (local time): 7MhtyX3aZEl9OUf8
[root@mysql ~]# mysql -uroot -p
Enter password:              –(此处复制粘贴 7MhtyX3aZEl9OUf8)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.2
Copyright (c) 2000, 2015, 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>  表示一切顺利成功。
mysql> SET PASSWORD = PASSWORD(‘123456’);  –设置密码为123456

5. 允许远程登陆
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,user,password from user;
+———–+——+——————————————-+
| host      | user | password                                  |
+———–+——+——————————————-+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql    | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
| 127.0.0.1 | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
| ::1      | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
+———–+——+——————————————-+
4 rows in set (0.00 sec)
mysql> update user set password=password(‘123456′) where user=’root’;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4  Changed: 3  Warnings: 0
mysql> update user set host=’%’ where user=’root’ and host=’localhost’;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit

6. 设置开机自启动
[root@mysql ~]# chkconfig mysql on
[root@mysql ~]# chkconfig –list | grep mysql
mysql          0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

7.  MySQL的默认安装位置
/var/lib/mysql/              #数据库目录
/usr/share/mysql              #配置文件目录
/usr/bin                    #相关命令目录
/etc/init.d/mysql              #启动脚本

8.  更改MySQL目录与字符集
[root@mysql01 /]# cd /
[root@mysql01 /]# mkdir data    #建立data目录
[root@mysql01 /]#  service mysql stop
Shutting down MySQL….                                    [  OK  ]
[root@mysql01 /]# mv /var/lib/mysql  /data  #把/var/lib/mysql整个目录移到/home/data
[root@mysql01 /]#  mkdir -p /data/mysql/binarylog
[root@mysql01 /]# chown -R mysql:mysql /data/mysql

如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf中
[root@mysql ~]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf    –修改配置文件位置
配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.
[root@mysql01 /]# cat /etc/my.cnf
[client]
password = 123456
port = 3306
default-character-set = utf8
[mysqld]
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql/
log_bin = /data/mysql/binarylog/binlog
[mysql]
default-character-set = utf8
socket  = /data/mysql/mysql.sock

查看字符集
show variables like ‘%collation%’;
show variables like ‘%char%’;

9. 重新启动MySQL服务
[root@mysql ~]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

OK  一切成功

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/219531.html<

(0)
运维的头像运维
上一篇2025-04-14 03:56
下一篇 2025-04-14 03:57

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注