centos6.5安装mysql5.6

11 篇文章 0 订阅
1. 先查看版本号
# uname -a

# cat /etc/redhat-release 
CentOS release 6.6 (Final)
2. 下载并安装Mysql的yum仓库

下载Mysql的yum仓库

http://dev.mysql.com/downloads/repo/yum/

然后安装一下这个仓库列表

$ sudo yum localinstall mysql-community-release-el6-5.noarch.rpm 
3. 搜索可安装的mysql版本

执行这个命令后就能看到可安装的mysql:

# yum repolist enabled | grep "mysql.*-community.*"

如果我们是要安装最新的版本,那么可以直接执行

# sudo yum install mysql-community-server

如果我们要选择版本,可以先执行下面这个命令查看一下有哪些版本:

# yum repolist all | grep mysql

如果要选择版本的话,有两种方式,一种是使用命令来

$ sudo yum-config-manager --disable mysql56-community
$ sudo yum-config-manager --enable mysql57-community-dmr

这个命令就是在仓库中启用5.7版本的,禁用5.6版本子仓库
或者编辑/etc/yum.repos.d/mysql-community.repo文件

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=//repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 

enabled=0表示禁用
比如要安装5.7版本的mysql,要确定5.6的enabled=0,5.7的enabled=1,一次保证只启用一个子仓库

# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

然后我们又可以愉快的安装mysql了

$ sudo yum install mysql-community-server

安装完成后我们启动mysql

$ sudo service mysqld start

查看mysql状态

$ sudo service mysqld status

启动mysql服务并初始化:

# /etc/init.d/mysqld start
Initializing MySQL database: 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h iZ94vana2fdZ password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

[ OK ]
Starting mysqld: [ OK ]
4. 初始化root密码

注意, 新版本的mysql数据库里的密码字段名不再是password了, 而是authentication_string

关闭mysql服务

# service mysqld stop

执行以下命令

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&

打开另一个终端窗口, 执行

# mysql

进入mysql shell, 如下:

# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.8-rc MySQL Community Server (GPL)

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> 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> update user set authentication_string = PASSWORD('123456') where user.user = 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

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

mysql> select user, host, authentication_string from user;
+------+-----------+-------------------------------------------+
| user | host      | authentication_string                     |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> 

设置完密码后, 退出执行mysqld_safe命令那个窗口, 重启下mysql服务, 再用执行以下命令并输入刚刚设置的密码进入mysql shell,

# mysql -uroot -p
5. 相关命令

启动mysql服务

# service mysqld start

重启mysql服务

# service mysqld restart

停止mysql服务

# service mysqld stop
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值