Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, October 11, 2016

Getting HTTP status code by cURL

I often use cURL command at the command line on Linux and OS X to fetch information by HTTP requests. Sometimes I just want to know only the HTTP status code. The option -v, which means verbose printing, prints too much information though I don't need.

-w "%{http_code}"

A more specific way to print out just the HTTP status code is something along the lines of:
$ curl -sI -o /dev/null -w "%{http_code}" http://www.example.org/
The option -w means to print assigned format below:
-w, --write-out 
        Make curl display information on stdout after a completed transfer. The format is a string that may
        contain plain text mixed with any number of variables. The format can be  specified  as  a  literal
        "string",  or  you  can  have curl read the format from a file with "@filename" and to tell curl to
        read the format from stdin you write "@-".

        The variables present in the output format will be substituted by  the  value  or  text  that  curl
        thinks  fit,  as  described  below. All variables are specified as %{variable_name} and to output a
        normal % you just write them as %%. You can output a newline by using \n, a carriage return with \r
        and a tab space with \t.

        NOTE: The %-symbol is a special symbol in the win32-environment, where all occurrences of % must be
        doubled when using this option.
Too simple and many format types are available. show man page to just type man curl. The option -I might be added to improve response load performance. This parameter just request for status headers of response, without download response body.

Thursday, August 11, 2016

Can't access MySQL 5.7 as root - Error 1698 (28000)

MySQL 5.7+ isn't allowed to login as root user without sudo because that secure model has been changed. The results of login appears ERROR 1698 (28000) as following output;

$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Skip grant tables to login

Stop the MySQL service for starting mysqld_safe.

$ sudo service mysql stop

Start the MySQL as safe mode with --skip-grant-tables to login without verification.

$ sudo mysqld_safe --skip-grant-tables

Connect to the MySQL as root.

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94
Server version: 5.7.14 MySQL Community Server (GPL)

Update mysql.user

It should be that the Plugin of root user sets auth_socket. The Plugin value will be modified to mysql_native_password for compatible former MySQL.

mysql> SELECT User, Host, Plugin FROM mysql.user;
+-----------+-----------+-----------------------+
| User      | Host      | Plugin                |
+-----------+-----------+-----------------------+
| root      | localhost | auth_socket           |
| mysql.sys | localhost | mysql_native_password |
+-----------+-----------+-----------------------+
2 rows in set (0.00 sec)
mysql> UPDATE mysql.user SET authentication_string = PASSWORD ('[root-password]'), Plugin = 'mysql_native_password' WHERE User = 'root';
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

Restart the MySQL

Restart the MySQL service and then enter via mysql-client after typed FLUSH PRIVILEGES. It should be solved.

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94
Server version: 5.7.14 MySQL Community Server (GPL)

That's it!