Pages

Saturday, January 4, 2014

Installing MySQL Server on a Red Hat Linux 6 System (64-bit)



1)      Requires root access on target server

2)      Download the latest stable MySQL release from http://www.mysql.com/downloads/ and unzip it. It requires login account on Oracle Software Delivery Cloud. Select a Product Pack as MySQL Database and Platform as Linux x86-64.

cd /tmp
# unzip V43500-01.zip
Archive:  V43500-01.zip
 extracting: MySQL-client-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-test-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-shared-compat-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-server-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-embedded-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-devel-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: MySQL-shared-advanced-5.6.16-1.el6.x86_64.rpm 
 extracting: README.txt   

3)      Remove the existing default MySQL.
# rpm -qa | grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
4)      MYSQL-shared-compat replaces the Red Hat mysql-libs package, thus satisfying dependencies of other packages on mysql-libs.
# rpm -ivh MySQL-shared-compat-advanced-5.6.16-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-shared-compat-adv########################################### [100%]
# rpm -ivh MySQL-shared-advanced-5.6.16-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-shared-advanced  ########################################### [100%]
# rpm -e mysql-libs
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
# rpm -ivh MySQL-server-advanced-5.6.16-1.el6.x86_64.rpm MySQL-client-advanced-5.6.16-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client-advanced  ########################################### [ 50%]
   2:MySQL-server-advanced  ########################################### [100%]
2013-12-19 21:02:09 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-12-19 21:02:10 2906 [Note] InnoDB: The InnoDB memory heap is disabled
2013-12-19 21:02:10 2906 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-12-19 21:02:10 2906 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-12-19 21:02:10 2906 [Note] InnoDB: Using Linux native AIO
2013-12-19 21:02:10 2906 [Note] InnoDB: Not using CPU crc32 instructions
2013-12-19 21:02:10 2906 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-12-19 21:02:10 2906 [Note] InnoDB: Completed initialization of buffer pool
2013-12-19 21:02:10 2906 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2013-12-19 21:02:10 2906 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2013-12-19 21:02:10 2906 [Note] InnoDB: Database physically writes the file full: wait...
2013-12-19 21:02:10 2906 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2013-12-19 21:02:11 2906 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2013-12-19 21:02:13 2906 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2013-12-19 21:02:13 2906 [Warning] InnoDB: New log files created, LSN=45781
2013-12-19 21:02:13 2906 [Note] InnoDB: Doublewrite buffer not found: creating new
2013-12-19 21:02:13 2906 [Note] InnoDB: Doublewrite buffer created
2013-12-19 21:02:13 2906 [Note] InnoDB: 128 rollback segment(s) are active.
2013-12-19 21:02:13 2906 [Warning] InnoDB: Creating foreign key constraint system tables.
2013-12-19 21:02:17 2906 [Note] InnoDB: Foreign key constraint system tables created
2013-12-19 21:02:17 2906 [Note] InnoDB: Creating tablespace and datafile system tables.
2013-12-19 21:02:17 2906 [Note] InnoDB: Tablespace and datafile system tables created.
2013-12-19 21:02:17 2906 [Note] InnoDB: Waiting for purge to start
2013-12-19 21:02:17 2906 [Note] InnoDB: 5.6.15 started; log sequence number 0
2013-12-19 21:02:21 2906 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2013-12-19 21:02:21 2906 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
A random root password has been set. You will find it in '/root/.mysql_secret'.
2013-12-19 21:02:24 2906 [Note] Binlog end
2013-12-19 21:02:24 2906 [Note] InnoDB: FTS optimize thread exiting.
2013-12-19 21:02:24 2906 [Note] InnoDB: Starting shutdown...
2013-12-19 21:02:25 2906 [Note] InnoDB: Shutdown completed; log sequence number 1625977

2013-12-19 21:02:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-12-19 21:02:26 2930 [Note] InnoDB: The InnoDB memory heap is disabled
2013-12-19 21:02:26 2930 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-12-19 21:02:26 2930 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-12-19 21:02:26 2930 [Note] InnoDB: Using Linux native AIO
2013-12-19 21:02:26 2930 [Note] InnoDB: Not using CPU crc32 instructions
2013-12-19 21:02:26 2930 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-12-19 21:02:26 2930 [Note] InnoDB: Completed initialization of buffer pool
2013-12-19 21:02:26 2930 [Note] InnoDB: Highest supported file format is Barracuda.
2013-12-19 21:02:26 2930 [Note] InnoDB: 128 rollback segment(s) are active.
2013-12-19 21:02:26 2930 [Note] InnoDB: Waiting for purge to start
2013-12-19 21:02:26 2930 [Note] InnoDB: 5.6.15 started; log sequence number 1625977
2013-12-19 21:02:26 2930 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2013-12-19 21:02:26 2930 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2013-12-19 21:02:26 2930 [Note] Binlog end
2013-12-19 21:02:26 2930 [Note] InnoDB: FTS optimize thread exiting.
2013-12-19 21:02:26 2930 [Note] InnoDB: Starting shutdown...
2013-12-19 21:02:28 2930 [Note] InnoDB: Shutdown completed; log sequence number 1625987

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.

In addition, you can run:
  /usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

# service mysql start
Starting MySQL......                                       [  OK  ]

5)      Perform post install security activities. The random password generated for root is in /root/.mysql_secret.
# /usr/bin/mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!


All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...



MySQL Installation Layout for Linux RPM packages.

Directory/File
Contents
/usr/bin
Client programs and scripts
/usr/sbin
The mysqld server
/var/lib/mysql
Databases, Log files
/usr/share/info
Manual in info format
/usr/share/man
Unix manual pages
/usr/include/mysql
Header files
/usr/lib/mysql
Libraries
/usr/share/mysql
Miscellaneous support files, error messages, character set files, sample configuration files, database install scripts
/usr/share/sql-bench
Benchmarks
/root/.mysql_secret
Default root password file
/usr/my.cnf
Configuration file
/usr/bin/mysql_secure_installation
Post install security script
/usr/bin/mysqlbug
Script to report any problems

# mysql -u root -p
Enter password:

Create user and grant privileges
mysql> CREATE USER 'abitra'@'localhost' IDENTIFIED BY 'passwd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'abitra'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'abitra'@'%' IDENTIFIED BY 'passwd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'abitra'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

The asterisks refer to the database and table respectively.

To display which accounts exist and check whether their passwords are empty.
mysql> SELECT User, Host, Password FROM mysql.user;
+--------+-----------+-------------------------------------------+
| User   | Host      | Password                                  |
+--------+-----------+-------------------------------------------+
| root   | localhost | *BEE13BB659FAA4D3ABFA2A849B1F9A6776DB65E2 |
| root   | 127.0.0.1 | *BEE13BB659FAA4D3ABFA2A849B1F9A6776DB65E2 |
| root   | ::1            | *BEE13BB659FAA4D3ABFA2A849B1F9A6776DB65E2 |
| abitra | %            | *4F281816E24012FEE52F4F5D469318355F9D482D |
+--------+-----------+-------------------------------------------+
4 rows in set (0.01 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema  |
| mysql                              |
| performance_schema |
+--------------------+
3 rows in set (0.05 sec)

mysql> CREATE DATABASE dbname;
mysql> DROP DATBASE dbname;
mysql > USE information_schema;
mysql> SHOW TABLES;

Startup and Shutdown MySQL Server

Execute any one of these commands to startup or shutdown MySQL database server.
Shutdown commands:
$ mysqladmin -u root -p shutdown
# service mysql stop
# /etc/rc.d/init.d/mysql stop

Startup commands:
$ /usr/bin/mysqld_safe &
# service mysql start
# /etc/rc.d/init.d/mysql start

Reset root password

If you don’t know the current password, start MySQL server to connect it without password.
# mysqld_safe --skip-grant-tables  &
# mysql -u root
mysql> UPDATE mysql.user SET password=PASSWORD(‘newpwd’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;
mysql> exit

If you know the password, connect to the server.
# mysql -u root -p
mysql> UPDATE mysql.user SET password=PASSWORD(‘newpwd’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;
mysql> exit

$ mysqladmin -u root -p


Configuration settings

The location for config file is /etc/mysql/my.cnf

[mysql]

# CLIENT #
port                           = 3306
socket                         = /var/lib/mysql/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /var/lib/mysql/mysql.sock
pid-file                       = /var/lib/mysql/mysqld.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000
#sql-mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
#sysdate-is-now                 = 1
#innodb                         = FORCE
#innodb-strict-mode             = 1

# DATA STORAGE #
datadir                        = /var/lib/mysql

# BINARY LOGGING #
log-bin                        = /opt/mysql/arch/mysql-bin
binlog_format = mixed
expire-logs-days               = 14
sync-binlog                    = 1

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 750
thread-cache-size              = 64
open-files-limit               = 65535
table-definition-cache         = 4096
table-open-cache               = 1024

#max_allowed_packet = 16M
#thread_stack = 256K
#query_cache_limit = 8M
#query_cache_size = 128M
#query_cache_type = 1
#table_cache = 1024
#wait_timeout = 300


# INNODB #
innodb-flush-method                 = O_DIRECT
innodb-log-files-in-group           = 2
innodb-log-file-size                     = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table                   = 1
innodb-buffer-pool-size              = 4G
innodb_log_buffer_size                   = 64M
#innodb_additional_mem_pool_size=20M
#innodb_lock_wait_timeout=50
#innodb_thread_concurrency = 8


# LOGGING #
#log-error                                     = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                             = 1
slow-query-log-file                      = /var/lib/mysql/mysql-slow.log

[mysqlbackup]

# BACKUP #
backup_dir                 = /opt/mysql/backup
socket                         = /var/lib/mysql/mysql.sock

To check what engine the tables are using

mysql> SHOW TABLE STATUS;

To check MySQL problem

mysql> SHOW ENGINE INNODB STATUS;

# innochecksum /var/lib/mysql/ibdata1

Reconfiguring InnoDB settings

1.       Stop MySQL.
# service mysql stop

2.       Edit the InnoDB setting as above.

3.       Move the below old InnoDB log files to backup location.
/var/lib/mysql/ib_logfile0
/var/lib/mysql/ib_logfile1

4.       Start MySQL.
# service mysql start

Saturday, November 30, 2013

Installing Oracle Application Express 4.2

Oracle APEX is a free browser based tool to develop web applications with SQL and PL/SQL for desktops and mobile devices. It is installed by default in all oracle database editions.

To verify APEX version.
SQL> SELECT schema, version FROM dba_registry WHERE comp_id = 'APEX';

SCHEMA       VERSION
------------------------------ ------------------------------
APEX_040000       4.0.2.00.09


To verify Oracle XML DB Protocol Server Port.
SQL> SELECT dbms_xdb.gethttpport FROM dual;

GETHTTPPORT
-----------
       8080

Disable Oracle XML DB protocol Server.
SQL> EXEC dbms_xdb.sethttpport(0);

Backup existing APEX binaries.
$ mv $ORACLE_HOME/apex $ORACLE_HOME/apex_040000

Unzip APEX software into ORACLE_HOME.
$ unzip apex_4.2.3_en.zip -d $ORACLE_HOME
$ cd $ORACLE_HOME/apex

SQL> CREATE TABLESPACE APEX_040200 DATAFILE '/u01/app/oracle/oradata/apex_423_01.dbf' SIZE 100M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;

SQL>@apexins.sql APEX_040200 APEX_040200 TEMP /i/

When APEX installs, it creates the below database accounts.
APEX_042000 - Owns APEX schema and metadata
FLOWS_FILES - Owns APEX uploaded files
APEX_PUBLIC_USER - Minimum privileged account used with APEX Listener or Oracle HTTP server with mod_plsql.

Change ADMIN account password.
SQL> @apxchpwd.sql

Configure the Embedded PL/SQL Gateway.
SQL> @apex_epg_config.sql /u01/app/oracle/product/11.2.0/xe
SQL> ALTER USER anonymous ACCOUNT UNLOCK;

If you are upgrading APEX, update the images directory.
SQL> @apxldimg.sql /u01/app/oracle/product/11.2.0/xe

SQL> ALTER USER apex_040200 ACCOUNT UNLOCK;
SQL> ALTER USER apex_public_user ACCOUNT UNLOCK;
SQL> ALTER USER flows_files ACCOUNT UNLOCK;
SQL> ALTER USER xdb ACCOUNT UNLOCK;

Set database parameters for APEX.
SQL> ALTER SYSTEM SET job_queue_processes=20 SCOPE=both;
SQL> ALTER SYSTEM SET shared_servers=5 SCOPE=both;    --> Embedded PL/SQL Gateway uses shared server architecture.

Enable Oracle XML DB  Protocol Server. The Embedded PL/SQL Gateway runs in the Oracle XML DB Protocol Server in the Oracle Database.
SQL> EXEC dbms_xdb.sethttpport(8080);

Enable access for remote users (optional).
SQL> EXEC dbms_xdb.setListenerLocalAccess(l_access => FALSE);

Enable network services in Database 11g by granting connect privileges to any host for APEX_040200 user.

DECLARE
  ACL_PATH  VARCHAR2(4000);
BEGIN
  -- Look for the ACL currently assigned to '*' and give APEX_040200
  -- the "connect" privilege if APEX_040200 does not have the privilege yet.

  SELECT ACL INTO ACL_PATH FROM DBA_NETWORK_ACLS
   WHERE HOST = '*' AND LOWER_PORT IS NULL AND UPPER_PORT IS NULL;

  IF DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE(ACL_PATH, 'APEX_040200',
     'connect') IS NULL THEN
      DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(ACL_PATH,
     'APEX_040200', TRUE, 'connect');
  END IF;

EXCEPTION
  -- When no ACL has been assigned to '*'.
  WHEN NO_DATA_FOUND THEN
  DBMS_NETWORK_ACL_ADMIN.CREATE_ACL('power_users.xml',
    'ACL that lets power users to connect to everywhere',
    'APEX_040200', TRUE, 'connect');
  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL('power_users.xml','*');
END;
/
COMMIT;

Login as ADMIN to Administrative Services for creating a workspace and APEX users at
http://locahost:8080/apex/apex_admin

Login as ADMIN to INTERNAL workspace at
http://localhost:8080/apex

Drop older version of APEX.
SQL> DROP USER apex_040000 CASCADE;

APEX Listener is a J2EE based alternative for Oracle HTTP Server (OHS) with mod_plsql.
To use APEX Listener, Disable Oracle XML DB Protocol Server.

SQL> EXEC dbms_xdb.sethttpport(0);

Configure RESTful Services.
SQL> @apex_rest_config.sql

When configuring RESTful Services, it creates two additional database accounts.
APEX_LISTENER - To query RESTful Services definitions.
APEX_REST_PUBLIC_USER - To call RESTful Services definitions.

Unzip APEX Listener software into ORACLE_HOME.
$ mkdir $ORACLE_HOME/apexlsnr
$ unzip apex_listener.2.0.5.287.04.27.zip -d $ORACLE_HOME/apexlsnr
$ cd $ORACLE_HOME/apexlsnr

Set the location for configuration files.
$ java -jar apex.war configdir $ORACLE_HOME/apexlsnr

Configure APEX Listener.
$ java -jar apex.war

This Listener instance has not yet been configured.
Please complete the following prompts

Enter the location to store configuration data:/u01/app/oracle/product/11.2.0/xe/apexlsnr
Nov 30, 2013 11:41:34 PM oracle.dbtools.common.config.cmds.ConfigDir execute
INFO: Set config.dir to /u01/app/oracle/product/11.2.0/xe/apexlsnr in: /u01/app/oracle/product/11.2.0/xe/apexlsnr/apex.war
Nov 30, 2013 11:41:38 PM oracle.dbtools.common.config.file.ConfigurationFolder logConfigFolder
INFO: Using configuration folder: /u01/app/oracle/product/11.2.0/xe/apexlsnr/apex
Enter the name of the database server [localhost]:
Enter the database listen port [1521]:
Enter 1 to specify the database service name, or 2 to specify the database SID [1]:
Enter the database service name:XE
Enter the database user name [APEX_PUBLIC_USER]:
Enter the database password for APEX_PUBLIC_USER:
Confirm password:
Enter 1 to enter passwords for the RESTful Services database users (APEX_LISTENER,APEX_REST_PUBLIC_USER), 2 to use the same password as used for APEX_PUBLIC_USER or, 3 to skip this step [1]:2
Nov 30, 2013 11:46:55 PM oracle.dbtools.common.config.file.ConfigurationFiles update
INFO: Updated configurations: defaults, apex, apex_al, apex_rt
Enter 1 if you wish to start in standalone mode or 2 to exit [1]:1
Enter the APEX static resources location or Enter to skip:/u01/app/oracle/product/11.2.0/xe/apex/images
Enter the HTTP port [8080]:

If you see "503 - Service Unavailable" message, reset the password and unlock the account for APEX_PUBLIC_USER.
SQL> ALTER USER apex_public_user IDENTIFIED BY <above_specified_password> ACCOUNT UNLOCK;

Configure an Administrator User to administer using SQL Developer.
$ java -jar apex.war user adminlistener "Listener Administrator"

Standalone mode doesn't support HTTPS. Disable the default behaviour to use OAuth2 in Non HTTPS Environments.
$ cd $ORACLE_HOME/apexlsnr
Add the following setting to the end of the file default.xml just before the </properties> tag.
<entry key="security.verifySSL">false</entry>

Start APEX Listener in standalone mode.
$ java -jar apex.war

To stop APEX Listener Server in standalone mode, press Ctrl-C.

To configure additional databases.
1. Create a database pool pointing to the database.
    java -jar apex.war setup --database <db_pool>
2. Create a new mapping rule.
    java -jar apex.war map-url --type base-path --workspace-id <workspace> /<path_prefix> <db_pool>
The URL path starts with /apex/<path_prefix> will be mapped to the database.