在centos使用rpm包的方式安装mysql,以及更改root密码

在centos使用rpm包的方式安装mysql,对于centos官方实际推荐使用yum进行安装,下载安装的方式主要用于内网服务器不能连接外网yum源的情况。

下载包

首先根据centos版本在mysql的官网下载rpm安装包,我的centos版本为6.6,下载的安装包为"MySQL-5.6.26-1.el6.x86_64.rpm-bundle.tar"

进行安装

  • 首先进行解压

tar -xvf MySQL-5.6.26-1.el6.x86_64.rpm-bundle.tar

  • 然后先安装历史库包

sudo rpm -i MySQL-shared-compat-5.6.26-1.el6.x86_64.rpm

  • 卸载操作系统中原有的mysql包

sudo yum remove mysql-libs

  • 安装mysql服务端,实际的数据库服务进程

rpm -i MySQL-server-5.6.26-1.el6.x86_64.rpm

  • 安装mysql客户端,用于连接数据库

sudo rpm -i MySQL-client-5.6.26-1.el6.x86_64.rpm

  • 安装之后的文件目录

/usr/bin Client programs and scripts
/usr/sbin The mysqld server
/var/lib/mysql Log files, databases
/usr/share/info MySQL manual in Info format
/usr/share/man Unix manual pages
/usr/include/mysql Include (header) files
/usr/lib/mysql Libraries
/usr/share/mysql Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation
/usr/share/sql-bench Benchmarks

启动使用

  • 安装过程中,会自动添加一个mysql用户和组,所以可以用这个用户或者root来启动mysql服务。

  • 使用rpm包安装默认添加了系统自动启动,可以使用service mysql stop从系统级别来停止mysql服务。

  • 一般情况下,首次登陆时可以通过空密码登陆,然后登陆数据库之后修改密码,但是我在安装完之后重启了系统,再次登陆时就不能通过空密码进行登陆了。

最后使用下面的方式更改了密码。

[root@centos1 ~]# service mysql stop
Shutting down MySQL.. SUCCESS!
[root@centos1 ~]#
[root@centos1 ~]#
[root@centos1 ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 2097
[root@centos1 ~]# 151024 10:08:17 mysqld_safe Logging to '/var/lib/mysql/centos1.err'.
151024 10:08:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql [root@centos1 ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 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> update user set password=PASSWORD('root') where user='root';
Query OK, 4 rows affected (0.06 sec)
Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye
[root@centos1 ~]# mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 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 Workbeach或phpMyAdmin中不显示或显示乱码的问题解决


下一篇:ssh的配置,ssh打开密钥登陆,关闭密码登陆。