18 October 2019

VirsualBox ต้องการขยายขนาด VMDK

HowTo: Extend VMDK on VirtualBox

When I first started using Oracle VirtualBox,
I would mostly stick with the default
options when creating a virtual machine.
I soon realized,
that wouldn't work for RDBMS installations,
and although I would just add new virtual disk drives,
I started to have unused or 100% full disks on some VMs.
Rather than delete the VM,
I decided to learn how to extend the existing disks,
the steps are listed below:
Note: The Oracle Virtualbox Hypervisor is installed on a Windows OS
Open a command prompt:
Change directories to the VirtualBox Installation
cd C:\Program Files\oracle\VirtualBox
List the info on the disk you want to resize
VBoxManage showhdinfo
“C:\Users\panong\VirtualBox VMs\CENTOS-6.7\D0.vmdk”

Run the command to resize:

VBoxManage modifyhd “C:\Users\panong\VirtualBox VMs
\CENTOS-6.7\D0.vmdk” --resize 50000
6.png
If you receive the error below, then you will have to
create a new disk, clone the data on the existing disk
to the new disk and then delete the original disk:
7.png
Create a new VMDK “dynamic” disk
VBoxManage createhd –filename “C:\Users\panong\VirtualBox VMs
\CENTOS-6.7\D11.vmdk” --size 50000

Clone old disk to the newly created disk
VBoxManage clonehd

“C:\Users\panong\VirtualBox VMs\CENTOS-6.7\D0.vmdk”
--existing “C:\Users\panong\VirtualBox VMs\CENTOS-6.7\D11.vmdk”

Release the old disk
Go to Virtualbox Media Manager ---> Select D0.vmdk --->
Click the "Release" option.

Note: DO NOT DELETE IT YET
Add the new disk to the Virtual Machine

Open the Machine folder and check the permission of
the created hard disk. If it doesn't have the
proper permission then it gives error while attaching
to the machine
Open the Settings of the Virtual Machine ---->
Storage ---> Add Hardisk -----> Select the hard disk that
was just created.
Make sure to remove all disks, then add the new one first
to be /dev/sda.
You're not done yet! If you start the VM now,
the disk space will not be present since it has not yet been
presented and allocated to your Linux Server.
To allocate the new disk, you will need to use
GParted - a GUI for editing disk partitions.
To download GParted,
go to http://gparted.sourceforge.net/livecd.php 
to download the ISO file named GParted Live CD (
Be sure to get the current version based on the architecture
of your OS e.g. 32-bit vs 64-bit). 
Create a new virtual machine for the
GParted ISO on a Linux OS.
Select Do not add a Hard Drive and ignore the warning.
Select the GParted VM, go to Settings ----->
Storage -----> Controller: IDE Controller -----> 
Add a new CD/DVD.
Add the GParted ISO file as the first item under
Controller: IDE section and delete any additional
empty disk slots. Add the disk that you wish to
resize( C:\Users\panong\VirtualBox VMs\CENTOS-6.7\D11.vmdk)
under the Controller: SATA Controller section -----> OK.
Start the GParted VM ----> GParted Live.
Do not change any of the default settings. 
Press the power button on the GParted VM to start it.
Now, you should have made a backup of your vdi at this point.
If you haven’t go back and do that
– so many things can go wrong here and you are on your own!
If it is any partition other
than /dev/sda1 you can right-click the partition
you wish to resize and choose Resize/Move.

IF YOU PREFER TO CREATE A NEW

PARTITION WITH THE ADDITIONAL

DISK SPACE YOU NEED TO CREATE A PARTITION:

Device —-> Create Partition Table
It should be back to main screen, click on
New —-> Add (it should have selected all the free space - 20000MiB) —-> Add
You should see it now listed as New partition #1
not unallocated anymore.
Click on Apply at the top of the GUI,
then confirm again by clicking Apply. Click Close.
You should now see the disk listed as /dev/sda# with 20Gb.
Exit the GParted VM.
Log on to the VM for the disk you just resized and
everything should be functional and the /dev/sda
drive should show the new size of 50Gb.
Delete the Original Disk Drive
Click the Remove option - this allows you to
keep the HDD without deleting it from the system if you choose.

*Cover Images from Oracle Corporation

-------------------------------------------------------------------
Credit : https://www.patricia-anong.com/blog/2017/11/1/extend-vmdk-on-virtualbox
----------------------------------------------------------------------------------

02 October 2019

ปัญหา XAMPP Error mysqli_real_connect(): (HY000/1130): Host 'localhost' is not allowed to connect to this MariaDB server

mysqli_real_connect(): (HY000/1130): Host 'localhost' is not allowed to connect to this MariaDB server


  1. Open XAMPP control panel
  2. Click MySQL > Config > my.ini
    XAMPP MySQL my.ini
  3.  Add below line under [mysqld] tag
    skip-grant-tables
    MySQL my.ini
  4. Save my.ini
  5. Restart MySQL server by pressing STOP and START button
  6. Now visit http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/
  7. Select mysql DB
  8. Repair the table named user by selecting checkbox then click on Repair table
    MySQL Table Repair
  9. Done..! 
However, you can now remove the line skip-grant-tables added in my.ini under [mysqld] tag, if you wantBecause it no more needed after successful implementation of 8th step. Hope, it could solve your error.

--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------

er

22 April 2019

คำสั่ง sql นับจำนวน Record ในฐานข้อมูล แยก ตาม field Date

เกริ่นนำก่อนนะครับ
พอดีผมมีฐานข้อมูล ที่มีการเก็บ รายละเอียดของข้อมูลโดยแต่ละ Record ถือเป็นข้อมูล 1 รายการ
และมีปัญหาว่า ผมไม่ได้เขียนโปรแกรมไว้สำหรับ ออกรายงาน เกี่ยวกับการนับจำนวนแยกตามเดือน
จึงได้ลองหา คำสั่ง sql เพื่อกรอง ข้อมูล สำหรับ ใช้งาน เฉพาะเป็นครั้งๆไป

Table ตัวอย่างนะครับ

id  |   end_date     | print  | note
------------------------------------
01 |  2018-01-01  |    1    | Null
02 |  2018-02-01  |    1    | Null
03 |  2018-03-01  |    1    | Null
04 |  2018-04-01  |    1    | Null
05 |  2018-05-01  |    1    | Null
06 |  2018-06-01  |    1    | Null
07 |  2018-07-01  |    1    | Null


ในที่นี้เราจะใช้คำสั่ง

SELECT DAY(Column)
SELECT MONTH(Column)
SELECT YEAR(Column)
ไว้เพื่อ กรุ๊ป วันเดือนปี ในที่นี้ ผมต้องการรวมแยกตามเดือน ก็เอามาแค่ เดือนกับปี

และจะใช้คำสั่ง count(Column) และ Group By เพื่อให้ผลของ sql ที่เรา query โชว์รายละเอียดเพิ่มเติ่มให้เราเห็นด้วย

SELECT year(end_date),month(end_date),count(id) FROM logs WHERE YEAR(end_date) = 2018 or year(end_date) = 2019 group by year(end_date),MONTH(end_date)

จากคำสั่ง sql นี้ ผมต้องการ field year,month,และให้ count field id เพื่อนับ
ส่วนเงื่อนไขก็คือ ให้ เอา ปี 2018 และ ปี 2019
โดยให้ จัดกลุ่มตาม ปี ตามด้วย เดือน

ผลลัพท์ที่ได้


year(end_date)month(end_date)count(id)
201814645
201823437
201834443
201843730
201853194
201863360
201873757
201888525
201899956
2018109509
2018119368
2018126282
2019110625
201928720
201939381
201946193

ตัวอย่างที่สองครับ แยกข้อมูลตามวันของเดือนนั้นๆ

SELECT year(end_date),month(end_date),day(end_date),count(id) FROM logs WHERE YEAR(end_date) = 2018 AND month(end_date) = 08 group by year(end_date),MONTH(end_date),day(end_date)

ผลลัพธ์ที่ได้


year(end_date)month(end_date)day(end_date)count(id)
201881216
201882221
201883258
201884278
201885154
201886302
201887258
201888233
201889357
2018810341
2018811193
201881256
2018813101
2018814320
2018815272
2018816308
2018817331
2018818257
2018819183
2018820322
2018821304
2018822303
2018823353
2018824333
2018825321
2018826236
2018827384
2018828328
2018829328
2018830330
2018831344


สำหรับใครที่มีปัญหาคล้ายๆผมก็ลองเอาไปประยุคใช้กันนะครับ