Mysql Installation Reference

* groupadd mysql
* useradd -r -g mysql mysql
* cd mysql
* chown -R mysql .
* chgrp -R mysql .

scripts/mysql\_install\_db --user=mysql

Make sure to run mysqld as mysql user:

sudo -u mysql ./mysqld\_safe &

sudo mkdir -p /var/run/mysqld

sudo chown mysql:mysql /var/run/mysqld

sudo mysqld\_safe --skip-grant-tables &

sudo mysql (This should take to the MySql Prompt)

UPDATE mysql.user SET password = '<password>' WHERE User = 'root';

update user set authentication\_string=PASSWORD("mysql") WHERE User = '<password>'; (for mysql version above 5.6 the column name is authentication\_string instead of password)

GRANT ALL PRIVILEGES on \*.\* to 'root'@'localhost' IDENTIFIED BY '<password>';

FLUSH PRIVILEGES;

### Custom DB User And Permissions

#### Creating User

CREATE USER '<db-user>'@'localhost' IDENTIFIED BY '<db-password>';

#### Creating Database

CREATE SCHEMA `<db-name>` CHARACTER SET utf8 COLLATE utf8\_bin;

#### Granting Permissions

GRANT ALL PRIVILEGES ON `<db-name>.\*` TO '<db-user>'@'localhost';
GRANT ALL PRIVILEGES ON `<db-name>`.\* TO '<db-user>'@'localhost';

### SQL Mode

#### To Check MYSQL mode

SHOW VARIABLES LIKE 'sql\_mode';

SELECT @@GLOBAL.sql\_mode global, @@SESSION.sql\_mode session

In case of of failure due to ONLY\_FULL\_GROUP\_BY and NO\_ZERO\_IN\_DATE need to clear both these

#### Disabling full group-by mode

SET SESSION sql\_mode=(SELECT REPLACE(@@sql\_mode,'ONLY\_FULL\_GROUP\_BY',''));

SET GLOBAL sql\_mode=(SELECT REPLACE(@@sql\_mode,'ONLY\_FULL\_GROUP\_BY',''));

#### Disabling full zero date mode

SET GLOBAL sql\_mode=(SELECT REPLACE(@@sql\_mode,'NO\_ZERO\_IN\_DATE',''));

SET GLOBAL sql\_mode=(SELECT REPLACE(@@sql\_mode,'NO\_ZERO\_DATE',''));

#### To clear SQL mode from configuration

Change file /etc/mysql/mysql.conf.d/mysqld.cnf

Paste below line on [mysqld] portion

sql\_mode = "STRICT\_TRANS\_TABLES,ERROR\_FOR\_DIVISION\_BY\_ZERO,NO\_AUTO\_CREATE\_USER,NO\_ENGINE\_SUBSTITUTION"

Original complete SQL Mode

sql\_mode="ONLY\_FULL\_GROUP\_BY,STRICT\_TRANS\_TABLES,NO\_ZERO\_IN\_DATE,ERROR\_FOR\_DIVISION\_BY\_ZERO,NO\_AUTO\_CREATE\_USER,NO\_ENGINE\_SUBSTITUTION"

Remember to restart mysql

sudo service mysql restart

### Enabling Logging

For logging to be enabled for all general logging MySql queries create a file under : /etc/my.cnf

```
In this file add the below contents:

```

```
[mysqld]

general_log_file        = /opt/mysql/logs/mysql.log

general_log             = 1

expire_logs_days        = 10

max_binlog_size         = 100M

```

Restart mysqld to enable logging.

The log will be written to the file mysql.log under the above location. Ensure that this file exisits and also that the user mysql has permission to write to this file.

To disable logging set the log value to zero

```
general_log             = 0

```

Restart mysqld. Further, different logs can be enabled; more info available here.

### Error Notes

In case of errors on shared object:

Set the path to the .so files in the lib folder (system so library files)

export LD\_LIBRARY\_PATH=$LD\_LIBRARY\_PATH:/lib/:/usr/lib/

#### Specific Errors

##### libaio

libaio.so.1: cannot open shared object file: No such file or directory

Run the below command:

sudo apt-get install libaio1 libaio-dev

##### libnuma

libnuma.so.1: cannot open shared object file: No such file or directory

Run the below command:

sudo apt-get install libnuma-dev