一、描述
本博客主要介绍CentOS6.5安装MySQL数据库 、启动和关闭MySQL服务、MySQL的登录和退出,以及My
SQL数据库root用户的密码配置和修改。
二、主要步骤
1、查看本系统是否已经安装有MySQL数据库
先查看本操作系统是否已经安装有操作系统,显示只有一个mysql的类库,并没有安装该数据库。
[[email protected] tongSoftware]$ rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
2、使用yum安装MySQL数据库,需要安装mysql客户端和mysql-server端
[[email protected] tongSoftware]$ sudo yum install mysql mysql-server
3、查看已安装数据库 ,显示安装完毕的数据库
[[email protected] tongSoftware]$ rpm -qa | grep mysql
mysql-server-5.1.73-3.el6_5.x86_64
mysql-5.1.73-3.el6_5.x86_64
mysql-libs-5.1.73-3.el6_5.x86_64
4、查看数据库的启动状态,如果未启动则启动MySQL数据库
[[email protected] tongSoftware]$ sudo service mysqld status
[sudo] password for tong:
mysqld is stopped
[[email protected] tongSoftware]$ sudo service mysqld start
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
5、默认无密码以root用户登录数据库
[[email protected] tongSoftware]$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved......
mysql>
6、输入exit退出数据库
mysql> exit
Bye
7、配置初始root密码
[[email protected] tongSoftware]$ sudo mysqladmin -u root password
Admin123
格式;mysqladmin -u 用户 password 密码
8、root用户使用密码登录数据库
[[email protected] tongSoftware]$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
9、修改用户密码
[[email protected] tongSoftware]$ sudo mysqladmin -u root -p password
Admin
Enter password:
格式:mysqladmin -u 用户 -p password 密码