Posts

Showing posts with the label mysql

MySQL DB Procedure Execution by a non-root user

Image
In my this blog, I'll share my experience of one of the issues that I faced during procedures execution for a migration project Problem Statement Recently I have been involved in an application migration project from one cloud to another cloud. I have done the database migration and due to security reasons, I have changed the identifier of all procedures to a non-root use so that I don't need to provide root credentials. However, One strange issue encountered during the procedure execution. Below is the sample snippet of my procedure I have been executing with a non-root user- CALL save_wallet_request('233284','23342sad','1','2021-01-13 06:54:23','eeedewewqewqeqe',@out_pgref_no,@out_dup_err)     Error Code: 1449. The user specified as a definer ('root'@'%') does not exist   0.107 sec Although I have a valid identifier in my procedure i.e. 'user001@%' but still I was not able to execute the procedure. Cause The proc...

MySQL Service start error on Ubuntu 16.04 VM- IP bind issue

Image
Problem Recently, my MySQL server 5.7.x wasn't starting rather it throws following error message Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.   MySQL Error Log-   /var/log/mysql/error.log 2020-07-20T14:34:56.131825Z 0 [Note] Server hostname (bind-address): '10.0.0.104'; port: 3306 2020-07-20T14:34:56.131862Z 0 [Note]   - '10.0.0.104' resolves to '10.0.0.104'; 2020-07-20T14:34:56.131895Z 0 [Note] Server socket created on IP: '10.0.0.104'. 2020-07-20T14:34:56.131913Z 0 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address 2020-07-20T14:34:56.131920Z 0 [ERROR] Do you already have another mysqld server running on port: 3306 ? 2020-07-20T14:34:56.132002Z 0 [ERROR] Aborting 2020-07-20T14:34:56.132037Z 0 [Note] Binlog end 2020-07-20T14:34:56.132157Z 0 [Note] Shutting down plugin 'ngram' 2020...

Installation of MySQL Server 8.0 Community on Ubuntu 16.04

Image
Hi everyone, in this post I'll write steps to install MySQL Server 8.0 on Ubuntu Linux 16.04 version. Below are the steps to be done for the same- 1. Setting up MySQL 8.0 Repository 2. De-packaginig Debian repository 3. Installing MySQL Server 8.0 Community Version 4. Creating new user, database, permission grant 5. Connecting MySQL Server via remote MySQL Workbench  1. Setting up MySQL 8.0 Repository First we need to setup repository for MySQL 8 as Ubuntu 16.04 doesn't get shipped with the same. In order to do so, visit the APT repo page and download the *.deb package as shown below- URL- https://dev.mysql.com/downloads/repo/apt/ Alternatively use CURL via command line/ terminal as follow- cd /tmp/  wget https://dev.mysql.com/get/mysql-apt-config_ 0.8.15-1 _all.deb 2. De-packaginig Debian package Now we need to de-package the Debian package as  sudo dpkg -i mysql-apt-config_ 0.8.10-1 _all.deb On...

MySQL Connectivity Common Errors

Image
In this post, I'll discuss some of the common errors being encountered during connection with MySQL Server and the best possible solution worked for me or someone- Problem-1 JDBC Connection Failure java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted to reconnect 3 times. Giving up  Solution Change JDBC url to include character encoding- jdbc:mysql://localhost:3306/databaseName? useUnicode=true&characterEncoding=utf8&useSSL=false &useLegacyDatetimeCode=false&noAccessToProcedureBodies=true&serverTimezone=UTC Problem-2 Connection Java-MySql: Public Key Retrieval is not allowed Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed Solution Change JDBC URL to include alllow Public Key Retrival true- jdbc:mysql://localhost:3306/databaseName? allowPublicKeyRetrieval=true &useSSL=false; Ref- https://mysqlconnector.net/connection-options/

MySQL 5.7.x unable to export sql output file (outfile)

Image
One of my colleague has asked about one strange issue where he created a shell script to export data from mysql in *.csv format at specific location and encountered issue while writing the files. Below is the summary of the same- Problem Cannot output MySQL data to file root@srv1:/MySQLBackup# ./script1.sh  mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000) at line 1: Access denied for user 'user'@'%' (using password: YES) mv: cannot stat '/created_files/data.csv': No such file or directory sed: can't read /created_files/data2020-04-15.csv: No such file or directory End of the Script The MySQL server is running with the --secure-file-priv option so it cannot execute this statement mv: cannot stat '/created_files/data.csv': No such file or directory script1.sh script1.sh master_db_user=user1 master_db_passwd=user1Pwd master_db_port=3306 master_db_host=localhost master_db_name=use...

MySQL 5.7.x reset 'root' password

Image
In this post I'll describe how can we set MySQL root password that was blank during the initial installation process. I'll describe end-to-end installation of MySQL database on a linux machine followed by resetting the root password. Environment OS Ubuntu Linux 18.04 MySQL 5.7.x JDK 1.8.x A. MySQL Installation Process 1. First, update the apt package index by typing (with sudo privileges): root@srv1:~# sudo apt update 2. Then install the MySQL package with the following command: root@srv1:~# sudo apt install mysql-server 3. Once the installation is completed, the MySQL service will start automatically. To check whether the MySQL server is running, type: root@srv1:~# sudo systemctl status mysql ● mysql.service - MySQL Community Server    Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)    Active: active (running) since Fri 2020-03-20 07:29:27 UTC; 17min ago   Process: 1649 ExecStart=/usr/sb...

MySQL procedure Insert error “Column count doesn't match value count at row 1”

Image
Recently I have came across a strange situation in MySQL Database. I have created a MySQL procedure that uses insert statement to insert values in database table. However, It was working fine previously but all of a sudden it stopped working with below error code- Problem Error Code: 1136. Column count doesn't match value count at row 1 Normally this error indicates my insert columns have a mismatch values i.e. consider a insert statement as shown below- insert into table1(col1,col2,col3,col4,col5) values(val1,val2,val4,val5) We can clearly see that col3 has a missing value in above statement i.e. mismatch of columns and corresponding values. However this was not a case with mine. Every column has corresponding value but still same error. Cause Upon close observation of other DB objects, I saw that there was a trigger associated with the table that has missing attributes and hence the same was causing error while inserting...

Developers- Free MySQL Database on Public IP

Image
Hi All, recently I had been struggling to get a free/opensource version of MySQL database for development perspective that can be readily available on public domain. After spending 10-15 mins on search, I found this wonderful website ( https://www.db4free.net/ ) that is made for developers to avail a free MySQL database and that in public domain. Below is the brief introduction of this website and how we can quickly get a MySQL DB instance- db4free.net provides a testing service for the latest - sometimes even development - version of the MySQL Database Server. You can easily create an account for free and test your applications.  db4free.net's MySQL server will be updated very soon after a new version is released, usually on the same day or very soon after. This cannot be used for production.  If you need a MySQL database for production use, please do not use db4free.net!  #Step1: SignUp Process Kindly refer to link https://www.db4free.net/...

MySQL Database basic administrative commands

Image
Hi folks, I am going to write some basic MySQL administrative commands in this post. So let's get started- Create New User in MySQL Database Login to MySQL with super user preferably root or user with full rights Execute below command CREATE USER 'username'@'hostname' IDENTIFIED BY 'YourPassword'; Example:  CREATE USER 'fmsuser'@'192.168.0.121' IDENTIFIED BY 'Pass1@210617'; Drop User in MySQL Database Login to MySQL with super user preferably root or user with full rights. Execute below command DROP USER 'username'@'hostname' Example:  DROP USER 'fmsuser'@'192.168.0.121' List All Users in MySQL Database  Login to MySQL with super user preferably root or user with full rights. Execute below command SELECT * FROM mysql.user Create New MySQL Database Login to MySQL with super user preferably root or user with full rights. Execute below command CREATE DATABASE newDBName DEFAULT CHARAC...