zoukankan      html  css  js  c++  java
  • yum安装Mysql

    环境:

    [wh42@e3ddba14 ABS_CORP]$ cat /etc/redhat-release

    CentOS release 6.3 (Final)

    [wh42@e3ddba14 ABS_CORP]$ uname -a
    Linux e3ddba14 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

    --安装Mysql:
    首先准备好mysql group和user
    [wh42@e3ddba12 ~]$ sudo groupadd mysql
    groupadd: cannot open /etc/group
    发现报错
    需要执行[wh42@e3ddba12 ~]$ sudo ulock

    [wh42@e3ddba11 ~]$ sudo groupadd mysql
    [wh42@e3ddba11 ~]$ sudo useradd -g mysql mysql
    其次安装mysql
    [wh42@e3ddba11 ~]$ sudo yum install -y mysql
    [wh42@e3ddba11 ~]$ sudo yum install -y mysql-server
    [wh42@e3ddba11 ~]$ sudo yum install -y mysql-devel
    修改/var/lib/mysql的权限
    [wh42@e3ddba11 lib]$ sudo chgrp -R mysql /var/lib/mysql
    [wh42@e3ddba11 lib]$ sudo chown -R mysql:mysql /var/lib/mysql/
    尝试连接mysql
    [wh42@e3ddba11 lib]$ mysql
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    检查发现该路径下的mysql.sock并不存在
    [wh42@e3ddba11 ~]$ cd /var/lib/mysql/
    [wh42@e3ddba11 mysql]$ ll
    total 0

    此时看到mysql服务并未启动
    [wh42@e3ddba11 mysql]$ sudo service mysqld status
    mysqld is stopped


    尝试启动mysql服务
    [wh42@e3ddba11 mysql]$ sudo service mysqld start
    Initializing MySQL database: 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 e3ddba12 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!

    [ OK ]
    Starting mysqld: [ OK ]

    [wh42@e3ddba11 mysql]$ ll
    total 20488
    -rw-rw---- 1 mysql mysql 10485760 Apr 1 22:30 ibdata1
    -rw-rw---- 1 mysql mysql 5242880 Apr 1 22:30 ib_logfile0
    -rw-rw---- 1 mysql mysql 5242880 Apr 1 22:30 ib_logfile1
    drwx------ 2 mysql mysql 4096 Apr 1 22:30 mysql
    srwxrwxrwx 1 mysql mysql 0 Apr 1 22:30 mysql.sock
    drwx------ 2 mysql mysql 4096 Apr 1 22:30 test


    此时连接mysql服务,修改root密码。
    [wh42@e3ddba11 bin]$ sudo service mysqld stop
    Stopping mysqld: [ OK ]

    [wh42@e3ddba11 bin]$ cd /usr/bin/
    [wh42@e3ddba11 bin]$ sudo mysqld_safe --user=root --skip-grant-tables --skip-networking
    140401 20:35:22 mysqld_safe Logging to '/var/log/mysqld.log'.
    140401 20:35:22 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

    新开一个窗口
    [wh42@e3ddba11 ~]$ 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.1.61 Source distribution

    Copyright (c) 2000, 2011, 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('wison') where user='root';
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 3 Changed: 0 Warnings: 0

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

    mysql> quit;
    Bye

    [wh42@e3ddba11 ~]$ sudo service mysqld start
    Starting mysqld: [ OK ]

    此时,就可以使用下面的命令连接到Mysql数据库
    [wh42@e3ddba11 ~]$ mysql -uroot -pwison
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.1.61 Source distribution

    Copyright (c) 2000, 2011, 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服务设置为随系统启动自动启动

    检查mysql服务是否自动启动

    [wh42@e3ddba12 ~]$ sudo chkconfig --list mysqld
    mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

    设置mysql服务随系统启动自动启动
    [wh42@e3ddba12 ~]$ sudo chkconfig mysqld on

    确认已经设置为自动启动,2-5必须为on
    [wh42@e3ddba12 ~]$ sudo chkconfig --list mysqld
    mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    之后测试是否自动重启

    [wh42@e3ddba12 ~]$sudo init 6

    当启动之后,可以看到

    [wh42@e3ddba11 ~]$ sudo service mysqld status
    mysqld (pid 1485) is running...

  • 相关阅读:
    为新项目添彩的 10+ 超有用 JavaScript 库
    c# 计算字符串和文件的MD5值的方法
    谷歌推出全新Android开发语言Sky:让App更流畅
    全面解析ECMAScript 6模块系统
    《HTML开发Mac OS App 视频教程》 第001讲、入门教程
    新兴技术袭来,Web开发如何抉择?
    jQuery仪表盘指示器动画插件 6种仪表样式
    4月份本周超过 10 款最新免费 jQuery 插件
    UI设计师必收!同行总结可即刻上手的iOS规范参考
    Angucomplete —— AngularJS 自动完成输入框
  • 原文地址:https://www.cnblogs.com/Wison-Ho/p/3639966.html
Copyright © 2011-2022 走看看