您的位置:首页 > 数据库 > MySQL

MySQL环境部署

2016-06-04 14:24 399 查看

MySql 环境部署

http://www.cnblogs.com/yyhh/p/5062153.html

本Markdown编辑器使用[StackEdit][6]修改而来,用它写博客,将会带来全新的体验哦:

序章:

MySQL是个小型的数据库,用来自己做小项目,做学习练习什么的再适合不过了,不过新手总会被一些莫名奇妙的问题难住,想要学习什么的,连环境都搭不好,简直是受罪,我也是个饱受这种痛苦的新手,所以想把遇到的问题都总结下来,以后再碰到,不用到处去找资料。

新手在Windows环境下,建议下载Installer MSI版本的,安装简单直接Next…直到Finish…完成安装,虽然只有32位的,但是作为学习练习,还是够用了(比如学习Java、Python、C#、SQL等语言),可不能输在搭建环境上,对吧!

但是还是有很多像我这样的强迫症患者,用了64位的操作系统,非要下64位的zip版本的MySQL心里才舒服。

MySQL下载地址:http://dev.mysql.com/downloads/mysql/

1.windows下安装mysql

下载最新版本的mysql



可以看到上图,MySQL5.7它没有data目录,如果没有data目录,安装后启动的时候就会报这个错:

D:\Service\mysql57\bin>net start mysql

MySQL 服务正在启动 .

MySQL 服务无法启动。

服务没有报告任何错误。

请键入 NET HELPMSG 3534 以获得更多的帮助。

为了避免这个错误,需要使用命令生成data文件夹,按如下步骤安装

首先需要将MySQL的bin录了添加到环境变量,bin目录下都是执行文件,如果没有放进环境变量,就需要进入到mysql的bin目录下执行相关指令

将my-default.ini修改为my.ini,并且放到bin目录下

修改my.ini,主要修改basedir和datadir,如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = D:\Service\mysql57
# datadir = D:\Service\mysql57\data
# port = .....
# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


进入dos的命令行,一定要用administrator进入。



进入MySQL的bin目录,输入mysqld –install可以安装MySQL

D:>cd D:\Service\mysql57\bin

D:\Service\mysql57\bin>mysqld -install

Service successfully installed.

输入以下命令,可以初始化MySQL数据库,初始化了之后,会打印出MySQL的默认生成的密码,下面标红了的就是默认生成的密码。

D:\Service\mysql57\bin>mysqld --initialize --user=mysql --console
2015-12-20T08:13:45.264865Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-20T08:13:45.854579Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-12-20T08:13:45.998772Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-20T08:13:46.098118Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9755c3ea-a6f1-11e5-81a3-74d02b122fb3.
2015-12-20T08:13:46.121617Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2015-12-20T08:13:46.135153Z 1 [Note] A temporary password is generated for root@localhost: g!gRw!d%M0Sj


初始化了以后,可以看到MySQL目录下,多了data目录



启动MySQL服务

D:\Service\mysql57\bin>net start mysql

MySQL 服务正在启动 .

MySQL 服务已经启动成功。

使用默认生成的密码,进入mysql

D:\Service\mysql57\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.10

Copyright (c) 2000, 2015, 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就可以修改默认密码了(我把默认密码修改成了root)

mysql> set password = password(‘root’) ;

这个时候,Windows下的MySQL环境就已经安装好了。

2、Linux下安装MySQL

如果有网络的话,Linux下安装就简单多了,我这用的CentOS安装的

安装MySQL服务,下面用yum安装,它会自动安装需要的依赖包,很方便,但是要用root用户来安装

[root@bogon ~]# yum install mysql-server

2. 启动MySQL服务,第一次启动服务会有点慢

[root@bogon ~]# /etc/init.d/mysqld restart

3. 启动了MySQL服务,就可以使用ps命令,可以查看到MySQL这个服务,说明服务已经启动了

[root@bogon ~]# ps -ef | grep mysql

root 3474 1 0 22:29 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe –datadir=/var/lib/mysql –socket=/var/lib/mysql/mysql.sock –pid-file=/var/run/mysqld/mysqld.pid –basedir=/usr –user=mysql

mysql 3576 3474 0 22:29 pts/0 00:00:00 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –user=mysql –log-error=/var/log/mysqld.log –pid-file=/var/run/mysqld/mysqld.pid –socket=/var/lib/mysql/mysql.sock

root 3614 3334 0 22:34 pts/0 00:00:00 grep mysql

4. 直接输入mysql就可以进入MySQL了

[root@bogon ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

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>

5. 设置MySQL的密码,我这边设置密码为root,以后就可以用这个密码来登录MySQL了

mysql> set password = password(‘root’);

Query OK, 0 rows affected (0.00 sec)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = D:\Service\mysql57
# datadir = D:\Service\mysql57\data
# port = .....
# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库