首頁 資料庫 mysql教程 mysql-5.6.15-win32安装及错误记录_MySQL

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

Jun 01, 2016 pm 01:26 PM
mysql 命名 資料夾 記錄

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
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
威爾R.E.P.O.有交叉遊戲嗎?
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

mysql:簡單的概念,用於輕鬆學習 mysql:簡單的概念,用於輕鬆學習 Apr 10, 2025 am 09:29 AM

MySQL是一個開源的關係型數據庫管理系統。 1)創建數據庫和表:使用CREATEDATABASE和CREATETABLE命令。 2)基本操作:INSERT、UPDATE、DELETE和SELECT。 3)高級操作:JOIN、子查詢和事務處理。 4)調試技巧:檢查語法、數據類型和權限。 5)優化建議:使用索引、避免SELECT*和使用事務。

phpmyadmin怎麼打開 phpmyadmin怎麼打開 Apr 10, 2025 pm 10:51 PM

可以通過以下步驟打開 phpMyAdmin:1. 登錄網站控制面板;2. 找到並點擊 phpMyAdmin 圖標;3. 輸入 MySQL 憑據;4. 點擊 "登錄"。

MySQL:世界上最受歡迎的數據庫的簡介 MySQL:世界上最受歡迎的數據庫的簡介 Apr 12, 2025 am 12:18 AM

MySQL是一種開源的關係型數據庫管理系統,主要用於快速、可靠地存儲和檢索數據。其工作原理包括客戶端請求、查詢解析、執行查詢和返回結果。使用示例包括創建表、插入和查詢數據,以及高級功能如JOIN操作。常見錯誤涉及SQL語法、數據類型和權限問題,優化建議包括使用索引、優化查詢和分錶分區。

為什麼要使用mysql?利益和優勢 為什麼要使用mysql?利益和優勢 Apr 12, 2025 am 12:17 AM

選擇MySQL的原因是其性能、可靠性、易用性和社區支持。 1.MySQL提供高效的數據存儲和檢索功能,支持多種數據類型和高級查詢操作。 2.採用客戶端-服務器架構和多種存儲引擎,支持事務和查詢優化。 3.易於使用,支持多種操作系統和編程語言。 4.擁有強大的社區支持,提供豐富的資源和解決方案。

redis怎麼使用單線程 redis怎麼使用單線程 Apr 10, 2025 pm 07:12 PM

Redis 使用單線程架構,以提供高性能、簡單性和一致性。它利用 I/O 多路復用、事件循環、非阻塞 I/O 和共享內存來提高並發性,但同時存在並發性受限、單點故障和不適合寫密集型工作負載的局限性。

MySQL和SQL:開發人員的基本技能 MySQL和SQL:開發人員的基本技能 Apr 10, 2025 am 09:30 AM

MySQL和SQL是開發者必備技能。 1.MySQL是開源的關係型數據庫管理系統,SQL是用於管理和操作數據庫的標準語言。 2.MySQL通過高效的數據存儲和檢索功能支持多種存儲引擎,SQL通過簡單語句完成複雜數據操作。 3.使用示例包括基本查詢和高級查詢,如按條件過濾和排序。 4.常見錯誤包括語法錯誤和性能問題,可通過檢查SQL語句和使用EXPLAIN命令優化。 5.性能優化技巧包括使用索引、避免全表掃描、優化JOIN操作和提升代碼可讀性。

MySQL的位置:數據庫和編程 MySQL的位置:數據庫和編程 Apr 13, 2025 am 12:18 AM

MySQL在數據庫和編程中的地位非常重要,它是一個開源的關係型數據庫管理系統,廣泛應用於各種應用場景。 1)MySQL提供高效的數據存儲、組織和檢索功能,支持Web、移動和企業級系統。 2)它使用客戶端-服務器架構,支持多種存儲引擎和索引優化。 3)基本用法包括創建表和插入數據,高級用法涉及多表JOIN和復雜查詢。 4)常見問題如SQL語法錯誤和性能問題可以通過EXPLAIN命令和慢查詢日誌調試。 5)性能優化方法包括合理使用索引、優化查詢和使用緩存,最佳實踐包括使用事務和PreparedStatemen

SQL刪除行後如何恢復數據 SQL刪除行後如何恢復數據 Apr 09, 2025 pm 12:21 PM

直接從數據庫中恢復被刪除的行通常是不可能的,除非有備份或事務回滾機制。關鍵點:事務回滾:在事務未提交前執行ROLLBACK可恢復數據。備份:定期備份數據庫可用於快速恢復數據。數據庫快照:可創建數據庫只讀副本,在數據誤刪後恢復數據。慎用DELETE語句:仔細檢查條件,避免誤刪數據。使用WHERE子句:明確指定要刪除的數據。使用測試環境:在執行DELETE操作前進行測試。

See all articles