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. cookie和session详解

    cookie和session的区别 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择,都纪录下来.当下次你再光临同 ...

  2. Windows Azure 虚拟机备份

    如果我们要在Windows Azure的虚拟机上进行一些“重要且高危”的操作,我们通常会想到使用快照或者备份功能.但是在Windows Azure上是没有虚拟机快照功能的,尽管我们可以对虚拟机的磁盘文 ...

  3. MySQL Database on Azure 的用户名

    MySQL Database on Azure是中国版Windows Azure上的一个PaaS服务,类似于AWS上的RDS.MySQL Database on Azure的用户名与on-premis ...

  4. AI (Adobe Illustrator)详细用法(四)

    本节主要是介绍和形状相关的操作. 一.外观面板的使用 熟悉外观面板的使用很重要. 1.新增描边 外观面板可以让我们增加多个描边. 点击“新增描边”,系统自动添加一个描边. 选中文字,新增描边,可以修改 ...

  5. 一起来啃书——PHP看书

    形式所迫,不得不开展android的学习,PHP这边也开始了啃书的日子.两部500+的书,45天够不,有点忙有点忙... 早上的胃胀,简直是一记闷棍,长点儿记性吧........ 1.PHP+MYSQ ...

  6. .Net工程详解及项目版本管理

    前言 写这篇文章的目地是为了让更多的小伙伴对VS生成的工程有一个清晰的认识.在开发过程中,为了赶进度,并不是每个人都有学习的时间. 但如果上层项目管理人员对这些工程目录不熟悉的话,把VS编译的中间文件 ...

  7. HOLOLENS的空间管理

    http://blog.csdn.net/sun_t89/article/details/52460272

  8. 更改项目名或者多个项目时,发现多个"Home"匹配的Controller时,解决方法

    [备份]异常信息:找到多个与名为“Home”的控制器匹配的类型.如果为此请求(“{controller}/{action}/{id}”)提供服务的 路由在搜索匹配此请求的控制器时没有指定命名空间,则会 ...

  9. web cache server方案比较:varnish、squid、nginx

    linux运维中,web cache server方案的部署是一个很重要的环节,选择也有很多种比如:varnish.squid.nginx.下面就对当下常用的这几个web cache server做一 ...

  10. flask01 安装及初涉

    一.安装 1.pip的安装 $ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py $ python get-pip.p ...