Home Database Mysql Tutorial mysql-5.6.15-win32安装及错误记录_MySQL

mysql-5.6.15-win32安装及错误记录_MySQL

Jun 01, 2016 pm 01:26 PM
mysql name folder Record

bitsCN.com 说明:这里是在win7下安装的,新版本的mysql安装与之前有不同。
1、下载mysql-5.5.20-win32.zip,解压到D:/dev,D盘的dev文件夹下就会出现mysql-5.5.20-win32目录,将其重命名为mysql。

2、配置MYSQL的环境变量
新增系统变量MYSQL_HOME: D:/dev/mysql
在PATH变量的最后面添加: ;%MYSQL_HOME%/bin
保存即可。

3、打开文件my-default.ini另存为my.ini,删除my.ini中的所有配置,在my.ini文件中加入如下简单配置:(my.ini是保存在与my-default.ini同一个目录下的)(#表示注释)
Mysql代码 收藏代码
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306

[mysql]
#设置mysql客户端的字符集
default-character-set = utf8

# The MySQL server
[mysqld]
port = 3306
#设置mysql的安装目录
basedir = D:/dev/mysql
#设置mysql数据库的数据存放目录,必须是data或者/xxx-data
datadir = D:/dev/mysql/data
#设置服务器段的字符集
character_set_server = utf8

4、注册服务

开始菜单,搜索cmd,单击右键“以管理员身份运行”,输入命令:

Mysql代码 收藏代码
mysqld --install mysql --defaults-file=d:/dev/mysql/my.ini

(如果此时“出现Install/Remove of the Service Denied!”的错误,说明cmd不是以管理员身份运行

或着,

开始菜单,搜索cmd,单击右键“以管理员身份运行”,输入命令:

Mysql代码 收藏代码
mysqld --install mysql

在“服务”中就会出现mysql这一项。 )

5、启动服务(开始菜单,搜索cmd,单击右键“以管理员身份运行”):

Mysql代码 收藏代码
net start mysql

(如果此时启动有问题,如1067错误,一般是你的my.ini文件有问题,你检查一下看看,如果确认没有问题,或者你更改过,那执行以下步骤:

%mysqlhome%/bin>mysqld-nt --remove

Service successfully removed.

然后重新执行步骤4

停止服务:

Mysql代码 收藏代码
net stop mysql

6、服务启动后:

登录MySQL服务器:

命令格式:

Mysql代码 收藏代码
mysql -h hostname -u username -p

(这里-h不要也可以,有可能出现can't connect to MySQL server on 'localhost'错误,这个需要修改windows的hosts文件,加上127.0.0.1 localhost)

Mysql代码 收藏代码
mysql -hhostname -uusername -p

命令说明:mysql命令将调用MySQL监视程序,这是一个可以将我们连接到MySQL服务器端的客户端命令行工具。

选项说明:

-h选项:用于指定所希望连接的主机,即运行MySQL服务器的机器。如果在运行MySQL服务器的机器上运行该命令,则可以忽略该选项和hostname参数;如果不是,必须用运行MySQL服务器的主机名称来代替主机名称参数。

-u命令:用于指定连接数据库时使用的用户名称。

-p命令:用于指定用户输入的密码

此时我本机安装了MYSQL,可忽略该选项和hostname参数:

Mysql代码 收藏代码
mysql -uroot -p

注:

MySQL的管理员用户名为root,密码默认为空 ,所以要你输密码时候直接回车即可

修改root密码

MySQL配置好后,启动成功,默认密码是空,但是为了安全,设置密码(MySQL有一个默认用户名为root,密码自己设定:假如设为root)。

1)登录MySQL root用户:

打开命令行,执行:

Mysql代码 收藏代码
mysql -uroot -p

2)修改root密码:

Mysql代码 收藏代码
mysql> update mysql.user set password="root" where User="root";
mysql> flush privileges;

修改该修改密码的语句:update mysql.user set password="root" where User="root";

为: update mysql.user set password=password("root") where User="root";

详细说明:见最底下的补充说明。

以后再进入MySQL,则为:

Mysql代码 收藏代码
mysql -uroot -proot

7、常用命令:

Mysql代码 收藏代码
create database new_dbname;--新建数据库
show databases;--显示数据库
use databasename;--使用数据库
select database();--查看已选择的数据库

show tables;--显示当前库的所有表
create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..)[ENGINE=engine_name];--创建表
create table tablename select statement;--通过子查询创建表
desc tablename;--查看表结构
show create table tablename;--查看建表语句

alter table tablename add new_fielname new_fieldtype;--新增列
alter table tablename add new_fielname new_fieldtype after 列名1;--在列名1后新增列
alter table tablename modify fieldname new_fieldtype;--修改列
alter table tablename drop fieldname;--删除列
alter table tablename_old rename tablename_new;--表重命名

insert into tablename(fieldname1,fieldname2,fieldnamen) valuse(value1,value2,valuen);--增
delete from tablename [where fieldname=value];--删
update tablename set fieldname1=new_value where filename2=value;--改
select * from tablename [where filename=value];--查

truncate table tablename;--清空表中所有数据,DDL语句

show engines;--查看mysql现在已提供的存储引擎:
show variables like '%storage_engine%';--查看mysql当前默认的存储引擎
show create table tablename;--查看某张表用的存储引擎(结果的"ENGINE="部分)
alter table tablename ENGINE=InnoDB--修改引擎
create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..) ENGINE=engine_name;--创建表时设置存储引擎

8、例如:

(1)登录MySQL服务器后,查看当前时间,登录的用户以及数据库的版本

Mysql代码 收藏代码
mysql> select now(),user(),version();
+---------------------+----------------+-----------+
| now() | user() | version() |
+---------------------+----------------+-----------+
| 2012-02-26 20:29:51 | root@localhost | 5.5.20 |
+---------------------+----------------+-----------+
1 row in set (0.00 sec)

(2)显示数据库列表

Mysql代码 收藏代码
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.03 sec)

(3)新增数据库并查看

Mysql代码 收藏代码
mysql> create database test_db;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| test_db |
+--------------------+
5 rows in set (0.00 sec)

(4)选择数据库

Mysql代码 收藏代码
mysql> use test_db;
Database changed

查看已选择的数据库:

Mysql代码 收藏代码
mysql> select database();
+------------+
| database() |
+------------+
| test_db |
+------------+
1 row in set (0.00 sec)

(5)显示当前数据库的所有数据表

Mysql代码 收藏代码
mysql> show tables;
Empty set (0.00 sec)

(6)新建数据表并查看

Mysql代码 收藏代码
mysql> create table person(
-> id int,
-> name varchar(20),
-> sex char(1),
-> birth date
-> );
Query OK, 0 rows affected (0.09 sec) Mysql代码 收藏代码
mysql> show tables;
+-------------------+
| Tables_in_test_db |
+-------------------+
| person |
+-------------------+
1 row in set (0.00 sec)

(7)获取表结构

Mysql代码 收藏代码
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

或者

Mysql代码 收藏代码
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

(8)查询表中的数据

Mysql代码 收藏代码
mysql> select * from person;
Empty set (0.00 sec)

(9)插入数据

Mysql代码 收藏代码
mysql> insert into person(id,name,sex,birth)
-> values(1,'zhangsan','1','1990-01-08');
Query OK, 1 row affected (0.04 sec)

查询表中的数据:

Mysql代码 收藏代码
mysql> select * from person;
+------+----------+------+------------+
| id | name | sex | birth |
+------+----------+------+------------+
| 1 | zhangsan | 1 | 1990-01-08 |
+------+----------+------+------------+
1 row in set (0.00 sec)

(10)修改字段的类型

Mysql代码 收藏代码
mysql> alter table person modify sex char(8);
Query OK, 1 row affected (0.17 sec)
Records: 1 Duplicates: 0 Warnings: 0

查看字段描述:

Mysql代码 收藏代码
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| sex | char(8) | YES | | NULL | |
| birth | date | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

(11)新增一个字段

Mysql代码 收藏代码
mysql> alter table person add(address varchar(50));
Query OK, 1 row affected (0.27 sec)
Records: 1 Duplicates: 0 Warnings: 0

查看字段描述:

Mysql代码 收藏代码
mysql> desc person;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| sex | char(8) | YES | | NULL | |
| birth | date | YES | | NULL | |
| address | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

(12)更新字段内容

查看修改前表的内容:

Mysql代码 收藏代码
mysql> select * from person;
+------+----------+------+------------+---------+
| id | name | sex | birth | address |
+------+----------+------+------------+---------+
| 1 | zhangsan | 1 | 1990-01-08 | NULL |
+------+----------+------+------------+---------+
1 row in set (0.00 sec)

修改:

Mysql代码 收藏代码
mysql> update person set name='lisi' where id=1;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from person;
+------+------+------+------------+---------+
| id | name | sex | birth | address |
+------+------+------+------------+---------+
| 1 | lisi | 1 | 1990-01-08 | NULL |
+------+------+------+------------+---------+
1 row in set (0.00 sec)

mysql> update person set sex='man',address='China' where id=1;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from person;
+------+------+------+------------+---------+
| id | name | sex | birth | address |
+------+------+------+------------+---------+
| 1 | lisi | man | 1990-01-08 | China |
+------+------+------+------------+---------+
1 row in set (0.00 sec)

为了方便下面测试删除数据,在向person表中插入2条数据:

Mysql代码 收藏代码
mysql> insert into person(id,name,sex,birth,address)
-> values(2,'wangwu','man','1990-01-10','China');
Query OK, 1 row affected (0.02 sec)

mysql> insert into person(id,name,sex,birth,address)
-> values(3,'zhangsan','man','1990-01-10','China');
Query OK, 1 row affected (0.04 sec)

mysql> select * from person;
+------+----------+------+------------+---------+
| id | name | sex | birth | address |
+------+----------+------+------------+---------+
| 1 | lisi | man | 1990-01-08 | China |
| 2 | wangwu | man | 1990-01-10 | China |
| 3 | zhangsan | man | 1990-01-10 | China |
+------+----------+------+------------+---------+
3 rows in set (0.00 sec)

(13)删除表中的数据

删除表中指定的数据:

Mysql代码 收藏代码
mysql> delete from person where id=2;
Query OK, 1 row affected (0.02 sec)

mysql> select * from person;
+------+----------+------+------------+---------+
| id | name | sex | birth | address |
+------+----------+------+------------+---------+
| 1 | lisi | man | 1990-01-08 | China |
| 3 | zhangsan | man | 1990-01-10 | China |
+------+----------+------+------------+---------+
2 rows in set (0.00 sec)

删除表中全部的数据:

Mysql代码 收藏代码
mysql> delete from person;
Query OK, 2 rows affected (0.04 sec)

mysql> select * from person;
Empty set (0.00 sec)

(14)重命名表

查看重命名前的表名:

Mysql代码 收藏代码
mysql> show tables;
+-------------------+
| Tables_in_test_db |
+-------------------+
| person |
+-------------------+
1 row in set (0.00 sec)

重命名:

Mysql代码 收藏代码
mysql> alter table person rename person_test;
Query OK, 0 rows affected (0.04 sec)

mysql> show tables;
+-------------------+
| Tables_in_test_db |
+-------------------+
| person_test |
+-------------------+
1 row in set (0.00 sec)

(15)新增主键

Mysql代码 收藏代码
mysql> alter table person_test add primary key(id);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc person_test;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| name | varchar(20) | YES | | NULL | |
| sex | char(8) | YES | | NULL | |
| birth | date | YES | | NULL | |
| address | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

删除主键:

Mysql代码 收藏代码
mysql> alter table person_test drop primary key;
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc person_test;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | 0 | |
| name | varchar(20) | YES | | NULL | |
| sex | char(8) | YES | | NULL | |
| birth | date | YES | | NULL | |
| address | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

(16)删除表

Mysql代码 收藏代码
mysql> drop table person_test;
Query OK, 0 rows affected (0.04 sec)

mysql> show tables;
Empty set (0.00 sec)

(17)删除数据库

Mysql代码 收藏代码
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| test_db |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database test_db;
Query OK, 0 rows affected (0.11 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

(18)查看建表语句

Mysql代码 收藏代码
mysql> show create table table_name;

补充说明:

update mysql.user set password="root" where User="root";修改的不是密码,如果按照这个方式修改了,重新登录时将会报错:

Mysql代码 收藏代码
mysql> update mysql.user set password="root" where User="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> exit
Bye

C:/Users/liqiong>mysql -uroot -p
Enter password: ****
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
ES)

请按照以下方式重新修改密码,即可登录成功:

Mysql代码 收藏代码
C:/Users/liqiong>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 4
Server version: 5.5.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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> update mysql.user set password=password("root") where User="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

C:/Users/liqiong>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 5
Server version: 5.5.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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>  bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Monitor Redis Droplet with Redis Exporter Service Monitor Redis Droplet with Redis Exporter Service Apr 10, 2025 pm 01:36 PM

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

See all articles