Showing posts with label MySql. Show all posts
Showing posts with label MySql. Show all posts

Tuesday, April 9, 2013

Install MySQL on Windows 7


Introduction


Download MySQL

Uninstall any previous versions through Control Panel prior to install.

MySQL is 'Open Source' software that is undergoing constant development.

At the time of writing this guide there are two later versions available
1. MySQL 5.5 is the current development release series
2. MySQL 5.1 is the current General Availability (Production) release series

I recommend you dowload the latest General Availability (GA) version as it has undergone extensive testing and is considered 'stable'.
To check which is the latest GA version click here - http://dev.mysql.com/doc/refman/5.1/en/choosing-version.html

The download you need for Windows is 'MSI Installer' for your system
mysql-essential-X.XX.XX-win32.msi - for 32 bit Windows OR
mysql-essential-X.XX.XX-winx64.msi - for 64 bit Windows


You must exit all other programs, in particular Anti Virus programs.

The install outlines here was on a 64bit system and is identical to 32 bit install.

Should you experience errors with the install - see NOTES below

Step 1

Navigate to the folder you downloaded to and click on install package.



Step 2

You may receive this security warning - click Run


Step 3

Click Next >


Step 4

You may select Typical if you are have a limited hard disk capacity.
I recommend Complete install.
Click Next >


Step 5

You are now ready to install - click Install


Step 6

Click Next >


Step 7

Click Next >


Step 8

Tick Configure the MySQL Server now
Registration is optional.
Click Finish


Step 9

Click Next >


Step 10

Your will only see this screen if you have previously installed or patrially installed this version of MySQL
If not previously installed go to Step 11
Select Reconfigure Instance then click Next >


Step 11

Select Detailed Configuration then click Next >


Step 12

Select Developer Machine then click Next >


Step 13

Select Non-Transactional Database Only then click Next >


Step 14

Select Decision Support (DSS)/OLAP then click Next >


Step 15

Select both (default) options: Enable TCP/IP Networking and Enable Strict Mode then click Next >


Step 16

Select (Default) Standard CharacteSet then click Next >


Step 17

Select both options: Install As Windows Service and Include Bin Directory in Windows Path then click Next >

Note: if you have installed an earlier version of MySQL the default Service Name: MySQL will not be available as it is already in use.
You MUST uninstall previous version to use the default Service Name


Step 18

If you have a previous install you must enter Current root password - if no previous install you will not see this
Enter New root password and Confirm
Make sure you record the Root Password
Note: The default username is root.
It is recommended to change this setting up PHPMyAdmin or MySQL Command Line Client (advanced)
Click Next >


Step 19

Click Execute to configure your database server.


NOTES
Should you receive any error messages when installing then cancel the install
Go to 'Control Panel' and remove MySQL
Before reinstalling shut down & restart then close all programs, including Anti Virus and reinstall.
If problem persists, more likely with 64 bit install, try downloading the current development release and installing.
Help can also be found at http://www.mysql.com/

NOTE: This drove me nuts for a while creating all sorts of errors in php code I was using
For some reason Microsoft thought we all required Military grade security and enabled 'Strict Mode' by default in MySQL.
This would only be required by securty & government agencies, eg my ISP disable on their server.
You can surf around on Google to read up on it & the various complex methods to disable it or keep reading.

To disable Strict Mode the easy way
Open your my.ini file
located at C:\Program Files\MySQL\MySQL Server 5.5\my.ini in your text editor (eg notepad)
Use control F (push Ctrl & F keys on keyboard together) and search for 'Strict'
locate this

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Change to this

# Set the SQL mode to strict
#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

or you can delete these lines altogether

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

by placing the hash (#) in front it disables Strict Mode

I recommend the (#) method so the lines are still there if you ever need enable 'Strict Mode' again (if you become a high security programmer!)

Then simply save the file in it's original location (eg click File then 'Save').

Mission Complete!!!




The next logical step is to install phpMyAdmin as a graphical front end - see link below.

Monday, April 8, 2013

MySql: Give Root User Logon Permission From Any Host


Note that this is Not very secure, and should only be used for a local development box where you don’t feel like setting up individual permissions, but still need to connect from other machines.
To configure this feature, you’ll need to update the mysql user table to allow access from any remote host, using the % wildcard.
Open the command-line mysql client on the server using the root account.
mysql -uroot
Then you will want to run the following two commands, to see what the root user host is set to already:
use mysql;
select host, user from user;
Here’s an example of the output on my database, which is pretty much the default settings. Note that ubuntuserv is the hostname of my server.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
+—————+——————+
| host | user |
+—————+——————+
| ubuntuserv | root |
| localhost | debian-sys-maint |
| localhost | root |
+—————+——————+
3 rows in set (0.00 sec)
Now I’ll update the ubuntuserv host to use the wildcard, and then issue the command to reload the privilege tables. If you are running this command, substitute the hostname of your box for ubuntuserv.
update user set host=’%’ where user=’root’ and host=’ubuntuserv’;
flush privileges;
That’s all there is to it. Now I was able to connect to that server from any other machine on my network, using the root account.
Again, note this isn’t very secure, and you should at least make sure that you’ve set a root password.

Tuesday, November 22, 2011

How to Change Database Collation to UTF-8

How to Change Database Collation to UTF-8


In some web hosting, They use Cpanel and Fantastico installer. It will automatic install your website and database. So You can not set your database collation by yourseft.

How to Change Database Collation 01 

Cpanel Interface



Bad luck, Some web hosting set the default database collation to Latin Swedish. But if you wanna do Thai, Chinese, Korean Website. You need to set the collation of database to UTF-8.

How to Change Database Collation 02

How to change this!!!!



If the database is not UTF-8, The display of your language will not display correctly.

How to Change Database Collation 03

As you can see in this picture.



Don't worry there's a way :)


For changing the collation of database, You can manually do it in notepad or dreamweaver.
But it's not very easy to do. So I will explain you the easiest way:

Step 1. You have to download Tool from Phoca for Changing Collation (Click here to Download). It's very great.

Step 2. After finish downloading, Right click and extract the file to your PC. (If you have WinZip, orWinRAR, etc.)

How to Change Database Collation 04

Step 3. You will see the folder name tool_phoca_changing_collation.... (Tooooo long name). Rename the folder to collation.

How to Change Database Collation 05

How to Change Database Collation 06

Rename the folder name to collation



Step 5. Uploading the folder to the root of your website.

How to Change Database Collation 07


Step 6. Okay, It's almost finish... Open your web browser and enter this URL: (Yourdomainname/collation/index.php)

How to Change Database Collation 08


Step 7. You will see this screen appear.

How to Change Database Collation 09

Step 8. Enter the field and click Submit
  • Database Host: Enter your host name
  • Database User: Enter your username for connecting to database
  • Database Password: Enter your password
  • Database Name: Enter your database name
  • Database Collation: utf8_general_ci


Step 9. Finish!!! Now the database change to UTF-8, Check your website and see the language display!

How to Change Database Collation 10
How to Change Database Collation 11


Thanks, Phoca Team Developer for this great stuff!!! :)

Monday, October 24, 2011

จะย้าย data path ใน MySQL 5.0 อย่างไร?


         หลักการทั่วไปของการย้าย data path บน MySQL 5.0 นั้น อาจดูซับซ้อนกว่า MySQL 3.23 ที่คุ้นเคย หรือกระทั้ง MySQL 4 ตัวผมเองนั้นผมเล่นจาก MySQL 3.23 แล้วว๊าปมาเป็นเวอร์ชัน 5.0 เลย เพราะไม่ชอบเวอร์ชัน 4 เอาเสียเลย เนื่องจากเป็นเวอร์ชันครึ่งผีครึ่งคนเกี่ยวกับภาษาไทย สมัยที่ผมยังเช่า hosting ชาวบ้านเขาที่ us-based server ผมเจอปัญหา 108 จริงๆ ครับ (โดยเฉพาะเรื่องภาษาไทย) หลังๆ ไม่เจอแล้วครับ เพราะมีเซิร์ฟเวอร์เป็นของตนเองแล้ว สั่งเองทุกอย่างได้ดังใจหมาย กว่าจะเก็บเล็กผสมน้อยจนพอมีเงินมาซื้อเซิร์ฟเวอร์เป็นของตัวเองได้ ก็เล่นเอาเหนื่อยชนิดหืดขึ้นคอเหมือนกันครับ :)
          สำหรับบน MySQL 5.0 นั้นสนับสนุน utf-8 (รหัสอักษร unicode เต็มพิกัด) ดังนั้นคุณจะไม่เจอปัญหาในการเก็บข้อมูลหลายๆ ภาษาลงบนฟิลด์เดียวกัน ไม่ต้องมานั่งแยกฟิลด์ของเทเบิลเพื่อเก็บแยกข้อมูลเหมือนในเวอร์ชันก่อนๆ เช่น ไทย อังกฤษ เยอรมัน  3 ภาษาฟิลด์เดียวกัน  อย่างนี้ไม่มีปัญหา เพราะถ้าไม่ใช่ระบบ unicode แล้ว สระภาษาไทยมันจะไปตีกับสระของภาษาเยอรมัน กลายเป็นไม้ตรี ไม้จัตวาปรากฏบนภาษาเยอรมันมั่ง หรือภาษาอะไรก็ตาม ที่ดันทะลึ่งไปมีโค้ดตรงกับสระของภาษาไทย ภาษานั้นจะมีปัญหาหมดครับ

วกกลับเข้าเรื่องกันต่อ หลักการติดตั้งให้ MySQL 5.0 มันเก็บ data path แยกไปตามที่ต้องการให้ทำดังนี้ครับ
          1. ในการติดตั้ง MySQL 5.0 ถ้าอยากให้ data path เก็บอยู่ที่ไดรฟ์ไหน ให้ติดตั้ง MySQL ไว้ที่ไดรฟ์นั้น เช่น ในคอมพิวเตอร์เรามีไดรฟ์ C และไดรฟ์ D เราอยากให้ข้อมูล data ของ MySQL อยู่ที่ไดรฟ์ D ก็ให้เราติดตั้ง MySQL ไว้ที่ไดรฟ์ D เช่น D:\MySQL5 หลังจากนั้น คุณผู้อ่านก็ติดตั้ง MySQL ไปตามปกติที่เคย (อย่าลืมสั่ง stop Apache ก่อนนะ แล้วก็อย่าลืมปิด Firewall application ก่อนจะเริ่มติดตั้ง MySQL ด้วยนะครับ โดยเฉพาะพวก Firewall application ทั้งหลายมันจะดัก port ไว้ ทำให้ MySQL ติดตั้งไม่ได้)
           2. พอติดตั้ง MySQL เสร็จแล้ว ให้ไปเปิดไฟล์ my.ini แล้วมองหาบรรทัดนี้ครับ (ถ้าคุณติดตั้ง MySQL ใน D:\MySQL5 ไฟล์ my.ini จะอยู่ที่                     
D:\MySQL5\my.ini)
#Path to the database root
datadir="D:/MYSQL5/Data/"
จากนั้นให้แก้เป็น path ที่คุณต้องการ เช่นผมอยากจะเก็บไว้ที่ d:/mysql_data/ ก็ให้พิมพ์แบบข้างล่างนี้ 
ข้อควรระวังให้ใช้ forward slash "/" นะครับ ไม่ใช่ back slash "\"
#Path to the database root
datadir="D:/mysql_data/"

          3. ถ้าคุณต้องการปรับแต่งเพิ่มเติม ก็ให้ดูบรรทัดต่อไปนี้เพิ่มด้วยก็ได้
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
บรรทัดข้างบนนี้ให้กำหนด default character set เป็น utf-8 ถ้าไม่ชอบก็เปลี่ยนได้ (แนะนำว่าเป็น utf8 นั้นดีที่สุดแล้วครับ)
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
ถ้าคุณไม่ชอบการกำหนด default engine เป็น INNODB ก็สามารถเปลี่ยน MyISAM ได้ ดังบรรทัดข้างล่าง
# The default storage engine that will be used when create new tables when
default-storage-engine=MyISAM
ความต่างของ INNODB กับ MyISAM ก็คือ MyISAM ทำงานได้เร็วกว่า แต่ไม่สามารถทำ loop back transaction ได้ ถ้าใช้เป็น INNODB จะสามารถทำ loop back transaction ได้ กรณีของ INNODB มักนิยมใช้กับ transaction ที่เกี่ยวกับระบบการเงิน หรือการชำระเงินเป็นต้น
เมื่อปรับ config เสร็จเรียบร้อยแล้วก็สั่ง save ไฟล์

         4. ไปที่โฟลเดอร์ D:\MYSQL5\data แล้ว copy ทั้งหมดที่มีในนั้น ไปไว้ที่ D:/mysql_data/"
(อย่าลืมสั่ง folder option ใน windows ให้แสดง hidden file กับ hidden system file ก่อนนะครับ ไม่งั้นจะมองไม่เห็นไฟล์อะไร)

ถ้า copy ถูกต้อง จะประกอบไปด้วยโฟลเดอร์ชื่อ mysql และ test แล้วก็มีไฟล์ ib_logfile0, ib_logfile1, ibdata1 และ microsof-xxxx (xxxx คือค่าที่ผันตามเครื่องคุณ)

         5. จากนั้นไปที่ start->setting->control panel->Performance and Maintenance->Administrative Tools->Services

พอเปิดส่วน Services ขึ้นมาแล้ว ให้มองหาบรรทัดที่เขียนว่า MySQL จากนั้นก็ drag ขวาที่บรรทัดนี้แล้วสั่ง stop แล้ว ค่อย start ใหม่

         6. ลองเปิดดู http://localhost/phpmyadmin แล้วลองสร้าง table หรือ database อะไรก็ได้ แล้วไปดูที่ d:/mysql_data ว่ามีชื่อ table หรือ database ขึ้นตามนั้นไหม ถ้ามีก็เป็นอันว่าโป๊ะเช๊ะ ok เรียบร้อยแล้วหละครับ