zoukankan      html  css  js  c++  java
  • Linux安装MySql

    本文记录Linux安装MySql过程。

    环境:OS:Centos 6.5 x64 & MySql 5.1 x64

    1、系统检查

    检查是否已经安装MySql数据库。

    [root@master ~]# rpm -qa | grep mysql

    如果有安装,先卸载已经安装的MySql数据库。

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

    2、安装数据库

    [root@master ~]# yum install -y mysql-server mysql mysql-devel

    查看安装情况

    [root@master ~]# rpm -qi mysql-server
    Name        : mysql-server                 Relocations: (not relocatable)
    Version     : 5.1.73                            Vendor: CentOS
    Release     : 3.el6_5                       Build Date: 2014年02月13日 星期四 03时42分39秒
    Install Date: 2014年04月17日 星期四 19时38分28秒      Build Host: c6b9.bsys.dev.centos.org
    Group       : Applications/Databases        Source RPM: mysql-5.1.73-3.el6_5.src.rpm
    Size        : 25882723                         License: GPLv2 with exceptions
    Signature   : RSA/SHA1, 2014年02月13日 星期四 03时48分08秒, Key ID 0946fca2c105b9de
    Packager    : CentOS BuildSystem <http://bugs.centos.org>
    URL         : http://www.mysql.com
    Summary     : The MySQL server and related files
    Description :
    MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
    client/server implementation consisting of a server daemon (mysqld)
    and many different client programs and libraries. This package contains
    the MySQL server and some accompanying files and directories.

    3、管理数据库

    启动数据库

    [root@master ~]# service mysqld start
    初始化 MySQL 数据库: 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 master 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!
    
    [确定]
    正在启动 mysqld: [确定]

    为MySql的root用户设置密码,初始没有密码。

    [root@master ~]# mysqladmin -u root password 'mysql'

    登陆数据库

    [root@master ~]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 5
    Server version: 5.1.73 Source distribution
    
    Copyright (c) 2000, 2013, 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> insert into mysql.user(Host,User,Password) values("localhost","hive",password("hive"));
    Query OK, 1 row affected, 3 warnings (0.01 sec)

    刷新系统权限表

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

    测试新建用户

    [huser@master ~]$ mysql -u hive -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 10
    Server version: 5.1.73 Source distribution
    
    Copyright (c) 2000, 2013, 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> GRANT ALL PRIVILEGES ON *.* TO hive@localhost IDENTIFIED BY 'hive'; 
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

     创建数据库

    mysql> create database hive;
    Query OK, 1 row affected (0.01 sec)
  • 相关阅读:
    ASP.NET备份还原数据库
    ASP.NET的运行原理与运行机制
    Asp.net WebPages框架运行原理浅析(转)
    不要盲目选择定时器
    C# 如何用计时器Timer控件实现停留几秒再做切换窗体的操作
    使用System.Timers.Timer类实现程序定时执行
    C#启动一个外部程序(1)-WinExec
    几种类型的db,以及最新的db排名,看一下
    SharePoint 2013 讨论板列表"Connect to Outlook" 不可用解决方案
    Java可视化编程,基于布局管理器的UI设计
  • 原文地址:https://www.cnblogs.com/guarder/p/3707895.html
Copyright © 2011-2022 走看看