I'm using xampp to run mysql, and I've created a database for a lost and found website.
The database is really simple, only two tables are used:
students
&
lost_items
I am trying to insert data into the students table, but it keeps saying that this table is read only. I've read some solutions and they said I need to use sudo and set the group privileges, but where do I put in these commands?
I had same problem in ubuntu and xampp.
In file config, after block innodb set --> innodb_force_recovery = 1
sudo chmod 777 -R /opt/lampp/var/mysql
Сomment out line #innodb_force_recovery = 1
restart MySQL
Get your data directories by following commands.
sudo cat /etc/mysql/my.cnf | grep -i datadir
or
sudo cat /etc/my.cnf | grep -i datadir
sudo chown -cR mysql:mysql /Path/mysql/datadir/
And restart mysql process
/etc/init.d/mysql stop
/etc/init.d/mysql start
Hope this helps.
Related
I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.
After following the instructions in the website and making the following my.cnf file:
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF
log_error = /var/log/mysql/error.log
# Remove case sensitive in table names
lower_case_table_names=1
I get the following error:
2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
What should I change so that data dictionary is aligned to server settings?
So far, I can get it to work with a workaround (I originally posted on askubuntu): by re-initializing MySQL with the new value for lower_case_table_names after its installation. The following steps apply to a new installation. If you have already data in a database, export it first to import it back later:
Install MySQL:
sudo apt-get update
sudo apt-get install mysql-server -y
Stop the MySQL service:
sudo service mysql stop
Delete the MySQL data directory:
sudo rm -rf /var/lib/mysql
Recreate the MySQL data directory (yes, it is not sufficient to just delete its content):
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql
sudo chmod 700 /var/lib/mysql
Add lower_case_table_names = 1 to the [mysqld] section in /etc/mysql/mysql.conf.d/mysqld.cnf.
Re-initialize MySQL with --lower_case_table_names=1:
sudo mysqld --defaults-file=/etc/mysql/my.cnf --initialize --lower_case_table_names=1 --user=mysql --console
Start the MySQL service:
sudo service mysql start
Retrieve the new generated password for MySQL user root:
sudo grep 'temporary password' /var/log/mysql/error.log
Change the password of MySQL user root either by:
sudo mysql -u root -p
and executing:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPa$$w0rd';
afterwards, OR by calling the "hardening" script anyway:
sudo mysql_secure_installation
After that, you can verify the lower_case_table_names setting by entering the MySQL shell:
sudo mysql -u root -p
and executing:
SHOW VARIABLES LIKE 'lower_case_%';
Expected output:
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
As per this link, lower_case_table_names should be set together with --initialize option.
MySQL Documentation says
lower_case_table_names can only be configured while initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.
https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html
The best way to prevent this problem is :At first add
[mysqld]
lower_case_table_names=1
then start mysql service for first time.
But anyway if you have started the server already,to solve your problem:
1.stop mysql:
systemctl stop mysql
2.clean data directory or change the default, the following is for new installations , if you have data in your database BACK UP them beforehand
rm -rf /var/lib/mysql
3.Insert lower_case_table_names = 1 in your my.cnf:
[mysqld]
lower_case_table_names=1
4.Start again
systemctl start mysqld
To fix this issue,
Just take the backup of the existing db Schema using the following command inside bin folder (/usr/local/mysql/bin)
./mysqldump -uroot -p password > dump.sql
Once the backup is taken delete the existing data folder in Mysql Home(/usr/local/mysql/) using the command
rm -rf data
Now add the configuration as "lower_case_table_names=1" in my.cnf under MYSQLD section (/etc/my.cnf)
Now Initialize the data directory using the following command inside bin directory (/usr/local/mysql/bin)
For Secure mode
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console
For Insecure mode
./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console
Once the data directory initialized, For Insecure mode repeat the Installation again and For Secure mode use the root password which is initialized during the run time of data directory Initialization.
Now import the existing dump file inside the Mysql Server using the command inside (/usr/local/mysql/bin) directory
./mysql -uroot -p password < file.sql
If anyone runs into this issue now, if you already initialized mysql, meaning you already had it up and running and then this error occurred, just comment out this line in the my.ini file.
lower_case_table_names=
I did an update from Mysql 5.5 to 8.0 in a Centos 6 server without dumping the databases to a .sql file, I just copied the /var/lib/mysql directory to another location.
Now if I try to load mysqld service it crashes.
Being naive I deleted all the content of /var/lib/mysql and installed the service again, now it runs but now I do not know how to manually import the DB files to the directory (copy & paste of the folder does not work) in order to do a check of the DB and/or repair it.
rysnc should likely already be installed, but if it isn't you would:
sudo yum install rsync
Then
#make sure mysql isn't running
sudo service mysqld stop
#double check that there is no MySQL PID running
sudo ps aux | grep mysql
#move the new MySQL 8.0 data files out of the way
sudo mv /var/lib/mysql /var/lib/mysql.bak
#copy the original data files back to /var/lib/mysql
#note that the trailing / is required for both paths
sudo rsync -av /path/to/original/mysql/db/files/ /var/lib/mysql/
#change user and group ownership to mysql
sudo chown -R mysql:mysql /var/lib/mysql
#start MySQL
sudo service mysqld start
#run mysql_upgrade, replace {usernamehere} with the actual username
sudo mysql_upgrade -u {usernamehere} -p
Update:
You will need to downgrade the binaries to 5.5. Take a backup of each database once MySQL is running again and then upgrade in the following order:
5.6
5.7
8.0
You will need to run mysql_upgrade after each upgrade.
I removed mysql completely including configuration files and when I try to reinstall, there is no mysql.socket (I searched in /var/lib/mysql/ and there's nothing.
Typically you will see mysql.sock file when you start the mysql daemon process. This is create the sock file.
But you can also search and see whether it has created somewhere.
netstat -ln | grep -o -m 1 -E '\S*mysqld?\.sock'
or
you can check with this command:
% mysqladmin variables
If you want to create the file, you can do this
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This thread explains things in more details.
I'm on Kubuntu 12.04, and after installing mysql via an apt-get (mysql ver: 5.5.35), i'm trying to start mysql service, but I got this error:
sudo service mysql start
start: Job failed to start
So I googled this problem, it says i have to go to the /var/log/mysql/error.log
But my error.log file is empty :(
Then I checked the permissions
:
drwxr-s--- 2 mysql adm 4096 Apr 7 11:21 mysql
-rw-r----- 1 mysql adm 0 Apr 7 11:21 error.log
So I don't know what to do... Why this error ? Why is the error file empty ?
First make a backup of your /var/lib/mysql/ directory just to be safe.
sudo mkdir /home/<your username>/mysql/
cd /var/lib/mysql/
sudo cp * /home/<your username>/mysql/ -R
Next purge MySQL (this will remove php5-mysql and phpmyadmin as well as a number of other libraries so be prepared to re-install some items after this.
sudo apt-get purge mysql-server-5.1 mysql-common
Remove the folder /etc/mysql/ and it's contents
sudo rm /etc/mysql/ -R
Next check that your old database files are still in /var/lib/mysql/ if they are not then copy them back in to the folder then chown root:root
(only run these if the files are no longer there)
sudo mkdir /var/lib/mysql/
sudo chown root:root /var/lib/mysql/ -R
cd ~/mysql/
sudo cp * /var/lib/mysql/ -R
Next install mysql server
sudo apt-get install mysql-server
Finally re-install any missing packages like phpmyadmin and php5-mysql.
My problem was running out of memory. Digital ocean has great instruction for adding swap memory for Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
This solved the issue and enabled me to restart the Mysql that otherwise would not start.
Reinstallation will works because it will reset all the value to default. It is better to find what the real culprits (my.cnf editing mistake does happens, e.g. bad/outdated parameter suggestion during mysql tuning.)
Here is the mysql diagnosis if you suspect some value is wrong inside my.cnf : Run the mysqld to show you the results.
sudo -u mysql mysqld
Afterwards, fix all the my.cnf key error that pop out from the screen until mysqld startup successfully.
Then restart it using
sudo service mysql restart
In my case, it simply because the disk is full.
Just clear some disk space and restart and everything is fine.
In most cases, just purging the mysql-server package and re-installing it will do the job.
Run,
sudo apt-get purge mysql-server-5.1 mysql-common
followed by
sudo apt-get install mysql-server
This line did solve the issue in my case,
sudo apt clean
In my case, i do:
sudo nano /etc/mysql/my.cnf
search for bind names and IPs
remove the specific, and let only localhost 127.0.0.1 and the hostname
Check the file permissions, if edited
Fail:
$ sudo chmod 776 /etc/mysql/my.cnf
$ sudo service mysql restart
mysql stop/waiting
start: Job failed to start
Ok:
$ sudo chmod 774 /etc/mysql/my.cnf
$ sudo service mysql restart
stop: Unknown instance:
mysql start/running, process 9564
To help others who do not have a full disk to troubleshoot this problem, first inspect your error log (for me the path is given in my /etc/mysql/my.cnf file):
tail /var/log/mysql/error.log
My problem turned out to be a new IP address allocated after some network router reconfiguration, so I needed to change the bind-address variable.
In my case the problem was the /var/log disk full (check with df -h)
Just deleted some log files and mysql started, no big deal!
The given solution requires enough free HDD, the actual problem was the HDD memory shortage. So If you don't have an alternative server or free disk space, you need some other alternative.
I faced this error with my production server (Linode VPS) when I was running a bulk download into MySQL. Its not a proper solution but VERY QUICK FIX, which we often need in production to bring things UP FAST.
Resize our VPS Server to higher Hard Disk size
Start MySQL, it works.
Login to your MySQL instance and make appropriate adjustments that caused this error (e.g. remove some records, table, or take DB backup to your local machine that are not required at production, etc. After all you know, what caused this issue.)
Downgrade your VPS Server to previous package you was already using
In my case:
restart server
restart mysql
create .socket in directory
I had the same problem. But i discover that my hd is full.
$ sudo cat /var/log/upstart/mysql.log
/proc/self/fd/9: ERROR: The partition with /var/lib/mysql is too full!
So, I run
$ df -h
And I got the message
/dev/xvda1 7.8G 7.4G 0 100% /
Then I found out which folder was full by running the following command on the terminal
$ cd /var/www
$ for i in *; do echo $i; find $i |wc -l; done
This give me the number of files on each folder on /var/www. I logged into the folder with most files, and deleted some backup files, and i continued deleting useless files and cache files.
then I run $ sudo /etc/init.d/mysql start and it work again
Our Mysql queries use temporary tables which creates temporary files in the process. Currently the files are written to /tmp. How exactly can the path of the temp folder to which mysql writes to be changed?
You should edit your my.cnf
tmpdir = /whatewer/you/want
and after that restart mysql
P.S. Don't forget give write permissions to /whatewer/you/want for mysql user
Here is an example to move the mysqld tmpdir from /tmp to /run/mysqld which already exists on Ubuntu 13.04 and is a tmpfs (memory/ram):
sudo vim /etc/mysql/conf.d/local.cnf
Add:
[mysqld]
tmpdir = /run/mysqld
Then:
sudo service mysql restart
Verify:
SHOW VARIABLES LIKE 'tmpdir';
==================================================================
If you get an error on MySQL restart, you may have AppArmor enabled:
sudo vim /etc/apparmor.d/local/usr.sbin.mysqld
Add:
# Site-specific additions and overrides for usr.sbin.mysqld.
# For more details, please see /etc/apparmor.d/local/README.
/run/mysqld/ r,
/run/mysqld/** rwk,
Then:
sudo service apparmor reload
sources: http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html, https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
This is answered in the documentation:
Where MySQL Stores Temporary Files
On Unix, MySQL uses the value of the TMPDIR environment variable as
the path name of the directory in which to store temporary files. If
TMPDIR is not set, MySQL uses the system default, which is usually
/tmp, /var/tmp, or /usr/tmp.
On Windows, Netware and OS2, MySQL checks in order the values of the
TMPDIR, TEMP, and TMP environment variables. For the first one found
to be set, MySQL uses it and does not check those remaining. If none
of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system
default, which is usually C:\windows\temp.
if you dont have apparmor or selinux issues, but still get errorcode 13's:
mysql must be able to access the full path. I.e. all folders must be mysql accessible, not just the one you intend in pointing to.
example, you try using this in your mysql configuration: tmp = /some/folder/on/disk
# will work, as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some
# will not work, also as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some/folder/on/disk
This maybe helpful for MySql with AppArmor
stop mysql :
sudo /etc/init.d/mysql stop
Create directory called /somewhere/tmp
Edit Config:
sudo vim /etc/mysql/my.cnf # or perhaps sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
change
tmpdir = /somewhere/tmp/
Then
sudo vim /etc/apparmor.d/usr.sbin.mysqld
Add
# Allow data dir access
/somewhere/ r,
/somewhere/** rwk,
sudo chown -R root:root /somewhere
sudo chmod -R 1777 /somewhere
Restart
sudo /etc/init.d/apparmor reload
sudo /etc/init.d/mysql restart
You can also set the TMPDIR environment variable.
In some situations (Docker in my case) it's more convenient to set an environment variable than to update a config file.
Works for 5.7 on centos 8
mkdir /tmp/1 /tmp/1
semanage fcontext -a -t mysqld_db_t "/tmp/1(/.*)?"
restorecon -Rv /tmp/1
semanage fcontext -a -t mysqld_db_t "/tmp/2(/.*)?"
restorecon -Rv /tmp/2
to my.cnf tmpdir=/tmp/1:/tmp/2
sudo service mysql restart
If you are a MariaDB user, all this above apply, by don't forget to unlock the "home" protection by doing this.
touch /etc/systemd/system/mariadb.service.d/override.conf
nano /etc/systemd/system/mariadb.service.d/override.conf
Inside override.conf put this content and save.
[Service]
ProtectHome=false
Then run the following commands :
systemctl daemon-reload
/scripts/restartsrv_mysql
After restarting mysql, the variables can be checked by :
mysqladmin variables|grep tmp