Thứ Tư, ngày 17 tháng 9 năm 2014

MySQL: Reset Lost Root Password from UBUNTU (linux) environment

MySQL: Reset Lost Root Password

Here is a quick Step-by-Step “how to” which helps restoring MySQL root password that was lost/forgotten.
It happens to everybody, especially if several distributed (different) systems are maintained, where the password is not the same. Here is what needs to be done to restore it:
Step 1: Stop MySQL daemon if it is currently running
Depending on the operating system MySQL is installed on, the daemon can be checked/stopped differently. Here is an example on how to do it in Unix-like systems.
[ NOTE ]: You might need to run it as a Unix System superuser (root) - depending on 
          how the system is configured, and what permissions your Unix account is granted)
Here is how to stop/kill the existing mysql daemon, in case it is running:
      ps -ef | grep mysql      - checks if mysql/mysqld is one of the running processes.
 
      pkill mysqld             - kills the daemon, if it is running.
Note: if pkill (’process kill’) is not on a particular Unix system, use kill -9 ‘pid’, where ‘pid’ corresponds to processes that were found with ps -ef | grep mysql
Step 2: Run MySQL safe daemon with skipping grant tables
      mysqld_safe --skip-grant-tables &
Step 3: Login to MySQL as root with no password
      mysql -u root mysql
Step 4: Run UPDATE query to reset the root password
In MySQL command line prompt issue the following two commands:
      UPDATE user SET password=PASSWORD("ualue=42") WHERE user="root";
      FLUSH PRIVILEGES;
“ualue=42” is a common password for “The Hitchhiker’s Guide to the Galaxy” people which reads “Ultimate Answer to Life, the Universe, and Everything=42“
Step 5: Stop MySQL safe daemon
Follow the first two steps, but this time kill (pkill) “mysqld_safe” instead of “mysqld”
Step 6: Start MySQL daemon
Depending on the operating system (Unix-like examples):
      /etc/rc.d/rc.mysql start
OR
      /etc/init.d/mysql start
OR
      /etc/rc.5/mysql start
etc.. check existing MySQL configuration
Step 7: Root password is reset and ready to use
Password is reset. Privileges are flushed. Start MySQL and login as root with the password set in step 4:
      mysql -u root -p mysql
Note: sometimes (most of the time) ‘root user’ privileges are required for the system (OS) in order to stop/start processes

Thứ Năm, ngày 04 tháng 9 năm 2014

[How-To] Connect an Android device using MTP in Ubuntu 14.04 LTS


  1. After much looking around I was never able to find a how-to guide(or should I say the ones that did never worked)on how to connect my android tablet/phone to Ubuntu for file transfers, sure there's other means of doing it wireless via your LAN, but truth be told MTP and Ubuntu don't exactly see eye to eye and as such I hope the following guide I put together saves someone a lot of time and effort. This was performed on Ubuntu 14.04 LTS

    STEP 1
    Firstly we're going to need to install some of the common MTP apps that will be needed. Open up a terminal and type the following two lines one after the other.

    Code:
    sudo apt-get install libmtp-common mtp-tools libmtp-dev libmtp-runtime libmtp9
    Code:
    sudo apt-get dist-upgrade
    STEP 2
    Then we're going to amend the fuse.conf file. FUSE is an application that aims to provide a secure method for non privileged users to create and mount their own file system implementations. This option overrides the security measure restricting file access to the user mounting the file system. So all users (including root) can access the files. This option is by default only allowed to root, but this restriction can be removed with a change to the aforementioned fuse.conf file as follows:

    At the terminal type

    Code:
    sudo nano /etc/fuse.conf
    We want to remove the # from the below line of code for user_allow_other, like so...

    Code:
    #/etc/fuse.conf - Configuration file for Filesystem in Userspace (FUSE)
    
    #Set the maximum number of FUSE mounts allowed to non-root users.
    #The default is 1000.
    #mount_max = 1000
    
    # Allow non-root users to specify the allow_other or allow_root mount options.
    user_allow_other

    Now save the file by pressing Ctrl+x, press Y and then Enter.

    STEP 3

    We now need to set up some rules for our device that we plan on connecting, but before we do that we need to find out both the vendor and product id

    Connect your device via an available usb port and from terminal enter

    Code:
    lsusb
    This should bring up an output similar to the following

    Code:
    Bus 002 Device 003: ID 0fce:01b1 Sony Ericsson Mobile Communications AB 
    Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 006: ID 0461:4d65 Primax Electronics, Ltd 
    Bus 001 Device 005: ID 0846:9020 NetGear, Inc. WNA3100(v1) Wireless-N 300 [Broadcom BCM43231]
    You need to look for your device, in this instance my Sony Tablet is at the top of the list, the vendor id is 0fce and product id is 01b1

    STEP 4
    We're then going to amend the mtp udev rules as follows, from a terminal type

    Code:
    sudo nano /lib/udev/rules.d/69-mtp.rules
    Then add the below line of code

    Code:
    # Sony Xperia Z2 Tablet
    ATTR{idVendor}=="0fce", ATTR{idProduct}=="01b1", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
    Remember what you're changing here is the device name next to the #, this can be whatever you want, the # comments out the code, but for clarity and reference later I would choose the name of your tablet/phone and also the vendor id and product id, they should match what was seen when you issued the lsusb command earlier.

    Once done, save the file.

    STEP 5
    The next step would also be to add a line of code to the 51 android rules file, again from a terminal type

    Code:
    sudo nano /etc/udev/rules.d/51-android.rules
    Then add the following line of code

    Code:
    ATTR{idVendor}=="0fce", ATTR{idProduct}=="01b1", MODE=”0666"
    Remember what I have highlighted in red needs to be changed to your device product id and vendor id.

    Once that is done and the file is saved, remove any usb device currently connected and issue the following commands

    STEP 6

    Code:
    sudo service udev restart
    Then save any other remaining work you may have open and reboot the system.

    STEP 7
    Code:
    sudo reboot
    Once rebooted you should now be able to plug your Android device in(making sure the screen is unlocked) and VIOLA!!(or at least I hope) You will now be able to transfer data to/from your Android device via the much quicker and much more reliable MTP

    All feedback gladly welcome, would like to know if this has worked for this others too.
    Last edited by jdarby1983; May 28th, 2014 at 10:04 PM.

[GUIDE] Ubuntu & OnePlus One: unlock the bootloader, install TWRP and SuperSU.

[GUIDE] Ubuntu & OnePlus One: unlock the bootloader, install TWRP and SuperSU.

Discussion in 'Development' started by nguserJul 13, 2014.
  1. nguser

    nguserNinja Moderator

    If you are on Windows and you're having problems with ADB and USB drivers, you can follow my guide using an Ubuntu Linux virtual machine on VirtualBox. Follow this complementary walkthrough by@Rapante to know how to set everything up properly: [GUIDE] Set-up VirtualBox with Ubuntu on Windows to unlock the bootloader of the OnePlus One.

    -----------------------------------------------------------------------------------------------------------------
    Disclaimer
    I am not responsible of any damage or loss of data that may occur before, during and after the whole process. By following this guide, your warranty will not be voided.
    -----------------------------------------------------------------------------------------------------------------​

    Hello everyone,

    I wrote this walkthrough to show you how to unlock the bootloader, install TWRP custom recovery and gain root privileges on your OnePlus One by using Ubuntu Linux operating system.

    Some of the instructions in this guide are not mandatory to accomplish the task but I decided to include them anyway just for informational purposes because this guide is intended for novice users.

    This is my personal method and I will provide you with detailed information to avoid mistakes so read carefully and have fun.

    Requisites:
    • Backup your data before proceeding!
    • OnePlus One Global Version with factory settings (locked bootloader, stock recovery/CyanogenMod 11S);
    • Ubuntu Linux (I used Xubuntu 13.10 64bit, tag me in a comment and let me know if the walkthrough works on your version too);
    • SuperSU .zip file (latest version available here);
    • TWRP Recovery .img file (latest version available here. I used TWRP 2.7.1.0);

    Let's begin.


    Chapter 1: Developer options, Android debugging & Android Tools
    • Phase 1Developer options and Android debugging.
    Go to Settings > About phone and tap 7 times on Build number to enable Developer options. You will see a little pop-up that says "You have enabled development settings!".

    1_about_phone.png 2_build_number.png 3_development_settings_enabled.png
    Go back to Settings menu and scroll down to Developer options. Tap on it and then enable Android debugging. You will be asked to allow USB Debugging, confirm by tapping on OK.

    4_developer_options.png 5_android_debugging.png 6_allow_usb_debugging.png ​

    • Phase 2: Installing Android tools (ADB & Fastboot) on Ubuntu Linux.
    The android-tools package has been added to Ubuntu "Universe" repository starting from version 12.10 Quantal Quetzal. If you are using an older version then you may need to follow this guide to install android-tools via PPA.

    Open Software & Updates and make sure that Universe repository is enabled. If not, enable it and insert the password if requested. Click on Close, then on Reload to update the package list. Wait until the update process is over.

    7_universe_repository.png 8_universe_repository.png 9_universe_repository.png
    Open Terminal and run this command to install ADB and Fastboot tools:

    sudo apt-get install android-tools-adb android-tools-fastboot


    Chapter 2: Unlock the bootloader.


    In this chapter we will focus on the Linux Terminal rather than the phone. Don't be scared, it will be easy enough and you will have the opportunity to learn something new.


    Now you can connect the OnePlus One to your computer.

    Once the OnePlus One has been connected to your pc, open the Terminal and run this command:

    adb devices
    Check the phone. Your computer's RSA fingerprint will be shown and you will be asked to allow USB debugging. Confirm by tapping on OK.

    10_rsa_fingerprint.png
    Check the Terminal. It should look like this:

    11_adb.png
    If you see offline instead of device, run the adb devices command once again.

    Put your OnePlus One in Fastboot Mode by running this command:

    adb reboot-bootloader

    12_adb.png 13_fastboot_mode.png
    Commands in Fastboot Mode need Administrator privileges on your pc, that's why we will use sudo.

    Run this command to make sure that Fastboot Mode is working correctly:

    sudo fastboot devices
    Terminal should look like this:

    14_fastboot_devices.png ​

    Next command will unlock the bootloader:

    sudo fastboot oem unlock
    15_sudo_fastboot_oem_unlock.png
    The phone will reboot and it will restore factory settings. All personal data and settings will be lost. Once the reboot is complete, copy the SuperSU .zip file to your phone and then put the device back inFastboot Mode.


    Chapter 3: Install TWRP Recovery.


    Put the TWRP Recovery .img file on Desktop and rename it to twrp.img. On Terminal, change the current working directory by running this command:

    cd Desktop
    16_cd_desktop.png
    Install TWRP Recovery by running this command:

    sudo fastboot flash recovery twrp.img
    17_flash_recovery.png
    Warning: OTA updates can overwrite the recovery partition and restore the stock CyanogenMod Simple Recovery. To avoid this, go to Developer options on the OnePlus One and make sure thatUpdate CM recovery option is disabled.
    Now it's time to enter Recovery Mode. To do that, hold down Power button and Volume down.

    18_twrp.png


    Chapter 4: Install SuperSU.


    Here we are, it's time to install SuperSU.

    In TWRP Recovery tap on Install, scroll down to the SuperSU .zip archive and select it. Perform aswipe to confirm the installation and lastly reboot the OnePlus One.

    19_twrp_supersu_1.png 20_twrp_supersu_2.png 21_twrp_supersu_3.png 22_twrp_supersu_4.png
    Once the reboot is complete, open SuperSU and make sure that "Respect CM root settings" option is not checked. If it is, uncheck it. This is because CyanogenMod 11S does not include root controls like CyanogenMod 11 does. That option, if enabled, may cause problems with apps that require root permissions.

    23_supersu.png

    Congratulations, you made it!

    Enjoy the OnePlus One and leave a comment for questions and suggestions. Ciao!​


    Feel free to translate this guide in your language and share it on regional forums.
    Spread the knowledge ;)

    Italian translation here.

    This guide also works on the following Ubuntu releases:
    • Ubuntu 14.04 64bit

Thứ Ba, ngày 08 tháng 7 năm 2014

MSsql (sql server) convert Datetime / Timestamp into Unix timestamp (bigint)

select CURRENT_TIMESTAMP;

select CONVERT(BIGINT, DATEDIFF(S, '19700101', '20380119')) + CONVERT(BIGINT, DATEDIFF(S, '20380119', CURRENT_TIMESTAMP)) ;

select DateAdd(SECOND, CONVERT(BIGINT, DATEDIFF(S, '19700101', '20380119')) + CONVERT(BIGINT, DATEDIFF(S, '20380119', CURRENT_TIMESTAMP)), '1970-01-01T00:00:00.000') AS TIME_MS;


convert from unix time to sql server datetime:
SELECT DATEADD(s, mycolumn / 1000, '19700101') from mytable
 
It would seem that we could use "ms" instead of the "s" parameter and avoid division by 1000, since the data are stored in milliseconds in mycolumn. However, that created an overflow condition. My only guess is that the dataadd function uses integer math internally instead of bigint.
Next up, how to convert the other direction:
SELECT cast(DATEDIFF(s, '19700101', cast('2012-10-10 14:05:00.000' as datetime)) as bigint) * 1000 from mytable
 
You'll want to replace '2012-10-10 14:05:00.000' with your own date/time string. Again we have this overflow problem if we try to get milliseconds directly in datediff, so we have to multiply by 1000.
This is all well and fine, but my data was not in the GMT timezone. So I additionally need to convert through to my timezone (CST).
SELECT cast(DATEDIFF(s, '19700101', dateadd(hh, 5, cast('2012-10-10 14:05:55.000' as datetime))) as bigint) * 1000 from mytable
 
As before, replace '2012-10-10 14:05:55.000' with your own date/time string.



SQL SERVER – Few Useful DateTime Functions to Find Specific Dates


Recently I have recieved email from 
----TodaySELECT GETDATE() 'Today'----YesterdaySELECT DATEADD(d,-1,GETDATE()) 'Yesterday'----First Day of Current WeekSELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)'First Day of Current Week'----Last Day of Current WeekSELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)'Last Day of Current Week'----First Day of Last WeekSELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0)'First Day of Last Week'----Last Day of Last WeekSELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6)'Last Day of Last Week'----First Day of Current MonthSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)'First Day of Current Month'----Last Day of Current MonthSELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)))'Last Day of Current Month'----First Day of Last MonthSELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))'First Day of Last Month'----Last Day of Last MonthSELECTDATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))'Last Day of Last Month'----First Day of Current YearSELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)'First Day of Current Year'----Last Day of Current YearSELECTDATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0)))'Last Day of Current Year'----First Day of Last YearSELECT DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))'First Day of Last Year'----Last Day of Last YearSELECTDATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)))'Last Day of Last Year'
ResultSet:
Today
———————–
2008-08-29 21:54:58.967
Yesterday
———————–
2008-08-28 21:54:58.967
First Day of Current Week
————————-
2008-08-25 00:00:00.000
Last Day of Current Week
————————
2008-08-31 00:00:00.000
First Day of Last Week
———————–
2008-08-18 00:00:00.000
Last Day of Last Week
———————–
2008-08-24 00:00:00.000
First Day of Current Month
————————–
2008-08-01 00:00:00.000
Last Day of Current Month
————————-
2008-08-31 23:59:59.997
First Day of Last Month
———————–
2008-07-01 00:00:00.000
Last Day of Last Month
———————–
2008-07-31 23:59:59.997
First Day of Current Year
————————-
2008-01-01 00:00:00.000
Last Day of Current Year
————————
2008-12-31 23:59:59.997
First Day of Last Year
———————–
2007-01-01 00:00:00.000
Last Day of Last Year
———————–
2007-12-31 23:59:59.997
Reference : Pinal Dave (http://blog.SQLAuthority.com)