mysql安装

什么是数据库?

数据库(Database)是按照数据结构来组织、存储和管理数据的仓库。简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进行新增、截取、更新、删除等操作。严格来说,数据库是长期储存在计算机内、有组织的、可共享的数据集合。数据库中的数据指的是以一定的数据模型组织、描述和储存在一起、具有尽可能小的冗长度、较高的数据独立性和易扩展性的特点并可在一定范围内为多个用户共享。

现在几大主流的数据库也就属于 mysql,sqlserver,oracle,access等等。而Sqlserver和oracle属于收费的产品,虽然mysql也有收费版的,但免费的社区版已经能够满足我们的需求了。所以接下来我们就主要讲讲mysql的安装和使用。

MySQL是跨平台的产品,所以下载时要注意对应的版本。

windows平台安装

以mysql-5.7.16-winx64.zip为例简单叙述,当然也可以下载windows下的mysql去安装,我这里意安装mysql包为例。

下载路径

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

解压缩(我个人的解压缩路径,也可以自己重新选择)

E:数据库MYSQLmysql-5.7.13-winx64

修改配置文件mysql-default.ini 

先找到这一块代码
# These are commonly set, remove the # and set as required.
#basedir = ......
#datadir = ......
#port = 3306
# server_id = .....

后改成即可

# These are commonly set, remove the # and set as required.
basedir = E:数据库MYSQLmysql-5.7.13-winx64mysql-5.7.13-winx64
datadir = E:数据库MYSQLmysql-5.7.13-winx64mysql-5.7.13-winx64data
port = 3306
# server_id = .....

配置环境变量  

找到启动文件bin的路径添加到path路径。

打开计算机属性显示将此路径按下图添加进去就可

E:数据库MYSQLmysql-5.7.13-winx64mysql-5.7.13-winx64in  

管理员身份进去命令cmd终端下

执行mysqld.exe --initialize 命令后系统会自动帮我们创建data目录

E:数据库MYSQLmysql-5.7.13-winx64mysql-5.7.13-winx64in>mysqld.exe --initialize

执行 mysqld -install命令

E:数据库MYSQLmysql-5.7.13-winx64mysql-5.7.13-winx64in>mysqld -install
Service successfully installed.  //成功安装服务

此时你的mysql已经安装成功了

安装成功后默认以root用户登陆,没有密码,如果自己想改密码,也可以修改

修改root密码

C:UsersAdministrator>mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.13 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> use mysql;
Database changed
mysql> update user set authtication_string=Password('123456') where user="root";

#特别注意的是 有时写password报错时就写authtication_string即可

启动mysql服务,就可以对数据库进行操作了

net stop mysql  #关闭mysql
net start mysql  #启动mysql

linux平台下安装 

linux平台下安装想必windows就简单容易的多了

linux环境下安装mysql有两种方法

  1. 直接使用命令进行安装,比较容易
  2. 另一种是下载压缩包进行源码编译安装

以ubuntu环境为例使用命令安装

apt-get install mysql-server

输入两次相同密码即可

启动mysql服务

service mysql start     # 启动mysql
service mysql stop     # 关闭mysql
service mysql restart # 重启mysql

源码编译安装  

官方下载地址

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

以mysql-5.5.29-linux2.6-x86_64.tar.gz为例

解压缩

tar -xvf mysql-5.5.29-linux2.6-x86_64.tar.gz

进入到路径下

 cd mysql-5.5.29-linux2.6-x86_64
 ./configure
make
make install

即可

 

 

  

  

  

  

  

  

原文地址:https://www.cnblogs.com/flash55/p/5979039.html