阿里云centos6.5 安装mysql数据库

一、卸载掉原有的mysql

  1.查看系统上是否安装mysql

    rpm -qa | grep mysql  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库

    如果有的话就使用 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉。

    rpm -e mysql  // 普通删除模式

    rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

    # 注意删除配置文件
     /var/lib/mysql
     /etc/my.cnf

    删除完成后,就通过,rpm -qa | grep mysql 命令来查看mysql是否已经卸载成功!!

 二、使用 yum 重新安装mysql

  1.使用yum的方式来安装mysql,首先我们可以输入 yum list | grep mysql 命令来查看yum上提供的mysql数据库可下载的版本

  yum list | grep mysql    //产看yum上提供的mysql数据库可下载的版本。

  2.输入 yum install -y mysql-server mysql mysql-devel 命令将mysql   mysql-server mysql-devel都安装好(注意:安装mysql时我们并不是安装了mysql客户端就相当于安装好了mysql数据库    了,    我们还需要安装mysql-server服务端才行。结尾出现  “Complete!”表示安装成功。

  3.安装完成后使用 rpm -qi mysql-server 产看安装好的mysql -server的版本。

三、初始化配置mysql

 1. service mysqld start 启动 mysql。第一次启动mysql会初始化配置,

  初始化 MySQL 数据库: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

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 xiaoluo 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.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

 2.确定mysql安装无误能启动成功后开始配置mysql root 账号密码。

   关闭mysql 使用ctrl+c退出mysql。

   mysqladmin -u root password '123456' // 通过该命令给root账号设置密码为 123456;

    

  3、mysql设置开机自启动

   chkconfig --list | grep mysqld 命令来查看mysql服务是不是开机自动启动。

    chkconfig --list | grep mysqld mysqld

   0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

   chkconfig mysqld on 命令来将其设置成开机启动

[root@admin ~]# chkconfig mysqld on
[root@admin ~]# chkconfig --list | grep mysql
mysqld             0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

  设置完成后使用mysql -u root -p 命令来登录我们的mysql数据库了

  

  

猜你喜欢

转载自www.cnblogs.com/jiajia1213/p/10247000.html