文章目录


    1.MySQL基础知识

    瑞典MySQL AB公司开发,由SUN收购,而后SUN被甲骨文并购,目前属于Oracle公司。

    MySQL是一种关联数据库管理系统 由于其体积小、速度快、总体拥有成本低、MySQL软件采用了双授权政策,分为社区版和企业版。

    1.1MySQL版本及下载

    MySQL数据库版本相对比较繁杂。常见的有:Community社区版、Enterprise企业版。

    Community版是开源免费的,这也是我们通常用的MySQL的版本。可以满足绝大多数用户需求。

    Enterprise版,官方指出提供30天免费试用期。可进一步划分为MySQL标准版、MySQL企业版、MySQL集群版。官方提供付费服务。

    其中Community Server 可以直接从mysql 的官网下载。但Enterprice Edition只能从Oracle edelivery上下载,而Edelivery有时会屏蔽中国IP。

    MySQL各版本区别参见:

    ​http://www.admin10000.com/Document/62.html​

    下载mysql时注意区分版本细节及所应用的系统平台:linux(32/64) 、win(32/64)

    举例:

    • MySQL Community Server 5.6.20 win版本
      GA 是指软件的通用版本,一般指正式发布的版本 (Generally Available (GA) Release)
    • mysql-essential-5.1.60-win32.msi 是精简版,如果只需要mysql服务,就选择此版本。
    • mysql-5.1.60-win32.msi 是完整版,包含安装程序和配置向导,有MySQL文档。
    • mysql-noinstall-5.1.60-win32.zip 是非安装的zip压缩包,没有自动安装程序和配置向导,无安装向导
    • mysql-5.1.60.zip 是用于windows的Mysql源码压缩包
      linux版本
      http://www.mysql.com/downloads/网站上下载不了
      www.oracle.com/downloads 找mysql 注册用户, 选择操作系统平台和mysql版本 进行下载

    我们选用较简单的RPM 包来安装。

    1.2下载安装包

    Community Server下载地址:

    MySQL Community Server mysql社区版,开源、免费

    MySQL Enterprise Edition mysql企业版,非免费

    MySQL Cluster mysql集群版,开源、免费

    2.MySQL服务器安装和启动

    2.1查询服务器上已经安装的mysql

    在终端提示符输入:rpm -aq | grep mysql 命令。查询结果如下显示:
    qt-mysql-4.6.2-25.el6.x86_64
    mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
    mysql-bench-5.1.66-2.el6_3.x86_64
    mysql-devel-5.1.66-2.el6_3.x86_64
    libdbi-dbd-mysql-0.8.3-5.1.el6.x86_64
    mysql-test-5.1.66-2.el6_3.x86_64
    mysql-libs-5.1.66-2.el6_3.x86_64
    mysql-5.1.66-2.el6_3.x86_64
    mysql-connector-java-5.1.17-6.el6.noarch
    mysql-server-5.1.66-2.el6_3.x86_64
    注:各机器有可能不相同,软件列表视实际情况。

    2.2卸载旧的版本

    rpm -e 软件包名 --nodeps --allmatches (不理会依赖关系,删除所有上一步查出来的相同的mysql)
    [root@localhost home]# rpm -e mysql-connector-odbc-3.51.26r1127-1.el5 --nodeps --allmatches
    [root@localhost home]# rpm -e libdbi-dbd-mysql-0.8.1a-1.2.2 --nodeps --allmatches
    [root@localhost home]# rpm -e mysql-server-5.0.77-3.el5 --nodeps --allmatches
    [root@localhost home]# rpm -aq | grep mysql
    [root@localhost home]#
    将老版本的几个文件手动删除
    #rm -f /etc/my.cnf
    #rm -rf /var/lib/mysql
    #rm -rf /var/share/mysql
    #rm -rf /usr/bin/mysql*

    2.3安装

    解压.zip安装包

    sudo unzip V46610-01-MySQL Database 5.6.20 RPM for Oracle Linux  RHEL 6 x86 (64bit).zip

    得到如下软件包:

    MySQL-client-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-devel-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-server-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-embedded-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-shared-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-shared-compat-advanced-5.6.20-1.el6.x86_64.rpm

    MySQL-test-advanced-5.6.20-1.el6.x86_64.rpm

    README.txt

    2.3.1安装服务器

    rpm -ivh MySQL-server-advanced-5.6.****-1.el6.x86_64.rpm

    A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
    You will find that password in '/root/.mysql_secret'.
    You must change that password on your first connect,
    no other statement but 'SET PASSWORD' will be accepted.
    See the manual for the semantics of the 'password expired' flag.
    Also, the account for the anonymous user has been removed.
    In addition, you can run:
    /usr/bin/mysql_secure_installation
    which will also give you the option of removing the test database.
    This is strongly recommended for production servers.
    See the manual for more instructions.
    Please report any problems at http://bugs.mysql.com/
    The latest information about MySQL is available on the web at
    http://www.mysql.com
    Support MySQL by buying support/licenses at http://shop.mysql.com
    New default config file was created as /usr/my.cnf and
    will be used by default by the server when you start it.
    You may edit this file to change server settings

    2.3.2安装客户端:

    rpm -ivh MySQL-client-advanced-5.6.****-1.el6.x86_64.rpm

      说明:不安装mysql-client是不能使用mysql工具登陆到mysql数据库
    其他软件包选择性安装:
    #rpm -ivh MySQL-devel-advanced-5.6.20-1.el6.x86_64.rpm

    2.4登录Mysql

    修改默认密码:

    ​https://blog.51cto.com/yang/2892132​​ 常规(不过新的好像不行了已经,不行就用上面的那种)

    oracle收购Mysql后,新版的mysql刚安装完mysql后不能直接输入mysql登录数据库, 而是设置了默认free password密码,默认密码放在了/root/.mysql_secret文件中,登陆后需要修改密码。

    1. 查看文件寻找密码
      cat /root/.mysql_secret

    1. 以root用户身份登陆MySQL
      服务启动和关闭:
    service mysql start     
    service mysql stop

      ps -u mysql 可以查看mysql用户(安装MySQL时,系统自动创建该用户)的进程
    PID TTY TIME CMD
    7586 ? 00:00:50 mysqld 守护进程
    登陆服务器:
    mysql -u root –p
    输入从.mysql_secret中读到的密码登录。
    如果登录期间发生异常,无法登陆:
    使用root将mysql的后台进程kill -9 PID

    1. 修改密码
      mysql> set password=password('123456');   

        将密码设置为:123456
    密码修改成后,再次登录使用:
    $mysql -uroot -p123456 即可。

    1. 查看数据库
      mysql> show databases;

    1. 退出登录 quit/exit