access denied while creating database in mysql code example

Example: can't create table errno: 13 permission denied mysql

#1-fix permission
$ mysql -u root -p -e 'SHOW VARIABLES WHERE Variable_Name="datadir"'

#output
+---------------+-----------------------+
| Variable_name | Value                 |
+---------------+-----------------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------------+
 
#2- Check owner of each file
$ ls -lh /var/lib/mysql/
 
#3- Update to correct owner
$ sudo chown -R db_admin:server_name /var/lib/mysql/*

Tags:

Sql Example