MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。

一、Window版本

1、下载

 MySQL Community Server 5.7.16

 http://dev.mysql.com/downloads/mysql/

2、解压

如果想要让MySQL安装在指定目录,那么就将解压后的文件夹移动到指定目录,如:C:\mysql-5.7.16-winx64

3、初始化

MySQL解压后的 bin 目录下有一大堆的可执行文件,执行如下命令初始化数据:

 cd c:\mysql-5.7.16-winx64\bin

 mysqld --initialize-insecure

4、启动MySQL服务

执行命令从而启动MySQL服务

 # 进入可执行文件目录
cd c:\mysql-5.7.16-winx64\bin # 启动MySQL服务
mysqld

5、启动MySQL客户端并连接MySQL服务

由于初始化时使用的【mysqld --initialize-insecure】命令,其默认未给root账户设置密码

 # 进入可执行文件目录
cd c:\mysql-5.7.16-winx64\bin # 连接MySQL服务器
mysql -u root -p # 提示请输入密码,直接回车

输入回车,见下图表示安装成功:

到此为止,MySQL服务端已经安装成功并且客户端已经可以连接上,以后再操作MySQL时,只需要重复上述4、5步骤即可。但是,在4、5步骤中重复的进入可执行文件目录比较繁琐,如想日后操作简便,可以做如下操作。

a. 添加环境变量

将MySQL可执行文件添加到环境变量中,从而执行执行命令即可

【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MySQL的bin目录路径追加到变值值中,用 ; 分割】

如:
C:\Program Files (x86)\Parallels\Parallels Tools\Applications;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Python27;C:\Python35;C:\mysql-5.7.16-winx64\bin

如此一来,以后再启动服务并连接时,仅需:

 # 启动MySQL服务,在终端输入
mysqld # 连接MySQL服务,在终端输入:
mysql -u root -p

b. 将MySQL服务制作成windows服务

上一步解决了一些问题,但不够彻底,因为在执行【mysqd】启动MySQL服务器时,当前终端会被hang住,那么做一下设置即可解决此问题:

 # 制作MySQL的Windows服务,在终端执行此命令:
"c:\mysql-5.7.16-winx64\bin\mysqld" --install # 移除MySQL的Windows服务,在终端执行此命令:
"c:\mysql-5.7.16-winx64\bin\mysqld" --remove

注册成服务之后,以后再启动和关闭MySQL服务时,仅需执行如下命令:

 # 启动MySQL服务
net start mysql # 关闭MySQL服务
net stop mysql

二、Linux版本

1、采用二进制包安装mysql

二进制软件包名称

mysql-5.5.49-linux2.6-x8.6_64.tar.gz 

添加用户和组

groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
tail -1 /etc/passwd
id mysql

开始安装MySQL

 [root@template ]# mkdir -p /home/oldboy/tools
[root@template ]# cd /home/oldboy/tools
[root@template tools]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
[root@template tools]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
[root@template tools]# mkdir -p /application/
[root@template tools]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
[root@template tools]# ln -s /application/mysql-5.5.49/ /application/mysql
[root@template tools]# ls -l /application/mysql
lrwxrwxrwx 1 root root 26 10月 27 10:28 /application/mysql -> /application/mysql-5.5.49/ [root@template tools]# cd /application/mysql/
[root@template mysql]# ls -l support-files/*.cnf
-rw-r--r-- 1 7161 wheel 4691 3月 1 2016 support-files/my-huge.cnf
-rw-r--r-- 1 7161 wheel 19759 3月 1 2016 support-files/my-innodb-heavy-4G.cnf
-rw-r--r-- 1 7161 wheel 4665 3月 1 2016 support-files/my-large.cnf
-rw-r--r-- 1 7161 wheel 4676 3月 1 2016 support-files/my-medium.cnf
-rw-r--r-- 1 7161 wheel 2840 3月 1 2016 support-files/my-small.cnf #复制my.cnf 配置文件
[root@template mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
[root@template mysql]# mkdir -p /application/mysql/data
[root@template mysql]# chown -R mysql.mysql /application/mysql/

初始化数据库

 [root@template mysql]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
Installing MySQL system tables...
161027 10:30:22 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 1958 ...
OK
Filling help tables...
161027 10:30:23 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 1965 ...
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: /application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h template.com password 'new-password' Alternatively you can run:
/application/mysql/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 /application/mysql ; /application/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/

添加数据库文件

 [root@template mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
[root@template mysql]# chmod +x /etc/init.d/mysqld
[root@template mysql]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10880 Oct 27 10:31 /etc/init.d/mysqld

二进制默认路径为/usr/local/mysql 启动脚本里面的路径要更改

 [root@template mysql]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

启动mysql数据库

 [root@template mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!

检查mysql数据库是否启动

 [root@template mysql]# netstat -lntup|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2224/mysqld

设置mysql 开机自启动

 [root@template mysql]# chkconfig --add mysqld
[root@template mysql]# chkconfig mysqld on
[root@template mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

配置开机自启动

 echo "#mysql start by huzhihua at 2016-10-27" >>/etc/rc.local
echo "/etc/init.d/mysqld start" >>/etc/rc.local [root@template mysql]# tail -2 /etc/rc.local
#mysql start by huzhihua at 2016-10-27
/etc/init.d/mysqld start

配置mysql命令的全局使用路径

 [root@template mysql]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@template mysql]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@template mysql]# source /etc/profile
[root@template mysql]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

登录mysql

别外三种登录方法:

 mysql -uroot -p,
mysql -uroot
mysql -uroot -p 'oldboy123' [root@template mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.49 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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> exit #退出

请退出mysql,再设置密码

mysqladmin -u root password ''

2、采用yum的方式安装mysql

安装:

1
yum install mysql-server  

服务端启动

1
mysql.server start

mysql安装方法的更多相关文章

  1. Mysql安装方法介绍

    MySQL的yum安装方法 centos7默认不再使用mysql而是用mariadb来代替mysql [root@yxh6 ~]# yum install mysql-server 已加载插件:fas ...

  2. Linux的MySQL安装方法

    第一种: APT方式安装 在ubuntu系统的apt软件仓库中,默认存在MySQL数据库 在用户模式下使用命令:  apt/apt-get install mysql-server mysql-cli ...

  3. MySQL 安装方法

    所有平台的Mysql下载地址为: MySQL 下载. 挑选你需要的 MySQL Community Server 版本及对应的平台. Linux/UNIX上安装Mysql Linux平台上推荐使用RP ...

  4. MySql安装方法和配置、解决中文乱码

    MySql Server安装步骤 1安装MySql Server 2 安装MySqlServer管理工具 解压中文语言包,将文件复制到安装目录下覆盖 文件覆盖后,打开软件设置语言为中文(CN) 3 M ...

  5. 模拟生成环境的MySQL安装方法-通用二进制方式安装

    模拟生成环境的MySQL安装方法-通用二进制方式安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.并发响应用户请求的网络IO模型 1>.单进程 特点:一个进程响应一个请 ...

  6. linux系统下yum 安装mysql的方法

    菜鸟一个,记录下yum 安装mysql的方法,给需要的朋友也做个参考吧. 弄了个新vps,想安装最新版的mysql,网上查了相关资料,记录如下: 1.安装查看有没有安装过:          yum ...

  7. mysql 安装失败解决方法

    在安装mysql的过程中,出现的最麻烦的问题和解决方法 安装后,启动不成功,就卡了,程序就没有响应. 如何解决: 找到mysql安装目录下的 #Path to the database root da ...

  8. MySQL的热备percona-xtrabackup、innobackupex的安装方法

    http://blog.csdn.net/dbanote/article/details/13295727 http://blog.csdn.net/yangzhawen/article/detail ...

  9. 【Vegas原创】Mysql绿色版安装方法

    所谓的绿色版,就是没有installer的MySQL,完全需要靠人工来操作,好处是,重装系统后,只要再做一次本次配置,即可使用. 具体操作方法: 1,设置系统环境变量, 在Path中添加 D:\mys ...

随机推荐

  1. Effective Java 读书笔记

    创建和销毁对象 >考虑用静态工厂方法替代构造器. 优点: ●优势在于有名称. ●不必再每次调用他们的时候都创建一个新的对象. ●可以返回原返回类型的任何子类型的对象. ●在创建参数化类型实例的时 ...

  2. UVA 11817 Tunnelling the Earth --球面距离公式

    题意: 给出两点的经纬度,求两点的球面距离与直线距离之差. 解法: 我们先算出球面距离,然后可以根据球面距离算出直线距离. 球面距离公式: R*acos(sin(W1)*sin(W2)+cos(W1) ...

  3. 洛谷⑨月月赛Round2 P3392涂国旗[DP]

    题目描述 某国法律规定,只要一个由N*M个小方块组成的旗帜符合如下规则,就是合法的国旗.(毛熊:阿嚏——) 从最上方若干行(>=1)的格子全部是白色的. 接下来若干行(>=1)的格子全部是 ...

  4. NOIP2003加分二叉树[树 区间DP]

    题目描述 设一个n个节点的二叉树tree的中序遍历为(1,2,3,…,n),其中数字1,2,3,…,n为节点编号.每个节点都有一个分数(均为正整数),记第i个节点的分数为di,tree及它的每个子树都 ...

  5. Git/Github + TortoiseGit 使用教程

    前言 Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. 在github上有很多优秀的项目,一个伟大的学习宝库.本文分享使用tortoisegit对github/ ...

  6. netty5和4.x,3.x的一些区别

    http://item.congci.com/item/netty-5-0-4-0-xin-bianhua-he-zhuyi-dian

  7. java内存设置

    在上边红色框内加入java内存设置命令: -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m

  8. poj1637 Sightseeing tour

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8859   Accepted: 3728 ...

  9. PPT文档页数显示的增加和更新

    在PPT的右下角增加页数的显示能够帮助演讲者把握进度,所以会经常遇到需要把页数显示在右下角的情况,这次在制作ppt的时候也遇到了.因此在这里总结一下设置方法. 一.在右下角显示当前页数和总页数 1)获 ...

  10. python中的字符串操作

    #!/usr/bin/python # -*- coding: UTF-8 -*- ''' str.capitalize() ''' str = 'this is a string example' ...