mysql環境搭建

mysql綠色安裝版下載:http://pan.baidu.com/s/1bnx2JLlhtml

mysql環境搭建網上帖子已經比較多了,本人之因此還要寫是由於只是想記錄一下本身安裝的過程要點,砍去老生常談的內容java

1.須要下載2個東西,Microsoft.NET.exe和mysql-5.6.24mysql

2.先安裝Microsoft.NET.exe,這個徹底沒有什麼可說,一路next,只是要等待它安裝過程會下載些東西sql

3.解壓mysql-5.6.24,本人下載到的這個是免安裝版,解壓到C盤根目錄,而後這麼來數據庫

文件夾就取名爲mysql5.6oracle

4.這裏也是找的別人說的方法,親測成功的編輯器

在mysql5.6裏面有一個叫my-default.ini的文件,而後複製它的一個副本,並更名爲my.ini,而後內容以下:ide

[client]
port=3306
default-character-set=utf8
#客戶端字符類型,與服務端一致就行,建議utf8
[mysqld]
port=3306
character_set_server=utf8
#服務端字符類型,建議utf8
basedir=C:\mysql5.6
#解壓根目錄
datadir=C:\mysql5.6\data
#解壓根目錄\data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[WinMySQLAdmin]
C:\mysql5.6\bin\mysqld.exe 
#解壓根目錄\bin\mysqld.exe

5.配置一個MYSQL_HOME的系統環境變量,本人的配置就爲C:\mysql5.6,而後path末尾加入%MYSQL_HOME%\bin工具

6.執行一些個命令測試

mysqld -install

啓動MYSQL服務:net start mysql

中止MYSQL服務:net stop mysql

移出mysql服務:mysqld -remove

7.修改root密碼:

C:\mysql5.6\bin>mysql -uroot

mysql>show databases; 

mysql>use mysql;

mysql>delete from user where user="";

mysql>update user set password=PASSWORD('root') where user='root';

mysql>FLUSH PRIVILEGES; 

mysql>quit;

FLUSH PRIVILEGES:強制讓MySQL從新加載權限,即刻生效

8.登陸,此時登陸時可用以下命令:

C:\mysql5.6\bin>mysql -uroot -p

ENTERPASSWORD:root

9.經常使用命令

mysql>show databases;       顯示全部表

mysql>use mysql;            切換到表mysql         

mysql>show tables;          顯示錶的結構

部份內容是抄的別人的經驗,可是都是本身親測過。

10.mysql-front工具

這個就像是oracle的plsql同樣

安裝也是一路next便可

視圖->SQL編輯器

11.mysql的亂碼問題曾經風靡一時,因此在環境搭建的時候眼睛可要擦亮了是否是配置的utf-8

12.這裏給一個Java測試腳本

import java.sql.SQLException;

public class JDBCTest {

	/**
	 * @param args
	 * @throws SQLException
	 */
	public static void main(String[] args) throws SQLException {
		// 1.註冊驅動
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// 2.建立數據庫的鏈接
		// useUnicode=true&characterEncoding=utf8:支持中文
		java.sql.Connection conn = java.sql.DriverManager.getConnection(
				"jdbc:mysql://192.168.191.1:3306/mysql", "root", "root");

		// 3獲取表達式SQL
		java.sql.Statement stmt = conn.createStatement();

		// 4.執行SQL
		String sql = "select * from mytable";
		java.sql.ResultSet res = stmt.executeQuery(sql);

		// 5.打印結果集裏的數據
		while (res.next()) {
			System.out.print("the uuid: ");
			System.out.println(res.getString("uuid"));
			System.out.print("the idserial: ");
			System.out.println(res.getString("idserial"));
			System.out.print("the nameserial: ");
			System.out.println(res.getString("nameserial"));
			System.out.println();
		}

		// 測試插入數據庫的功能:
		// String inSql = "insert into test(user,addr) values('插入2','新地址2')";
		// stmt.executeUpdate(inSql);

		// 6.釋放資源,關閉鏈接(這是一個良好的習慣)
		res.close();
		stmt.close();
		conn.close();
	}

}

13.再給一個驅動包 http://pan.baidu.com/s/1ntBv9Y5

14.設置一下root遠程訪問的權限(關於Host '192.168.191.2' is not allowed to connect to this MySQL server問題)

grant all privileges on *.* to root@'%' identified by 'root';

上面這句話就是把全部數據庫(第一個*)的全部表(第二個*)的全部權限賦給root用戶,它能夠在任意機器(%)上進行登陸

15.建立一個用戶,並把全部權限賦給他

grant all on *.* to test@'%' identified by 'test';

16.建立一個數據庫,並在這個數據庫新建表

create database testDatabase;

use testDatabase;

create table TT(
    id int,
    name varchar(20),
    primary key(id)
);

https://www.cnblogs.com/yinzx/p/4623296.html

http://blog.csdn.net/only_wan/article/details/53700428

相關文章
相關標籤/搜索