How to change InnoDB AUTO_INCREMENT Lock Modes on Debian? - mysql

I create a table with auto_increment, and insert into it a lot of data.
My database skip number while I am using auto-increment, i found that i have to change the auto_incremet_lock_mode = 0, but i didn't find, where i have to do this change on Debian system?
I tried to find the my.cnf file in /etc/mysql/ but it contains only 2 rows, so i don't know how i can change it. I read the mysql site too but there isn't any information about it.

It was hard, but i found the answer!
edit the /etc/my.cnf file with
[mysqld]
innodb_autoinc_lock_mode=0
//You have to use autoinc_lock_mode inside this [mysqld] part!
restart/reload configs with sudo /etc/init.d/mysql restart

Related

cant make local database because Error: FIle/etc/my.cnf doesnt exist

i want to make local database on workbench and when i configure local management it was said
Check if /etc/my.cnf can be accessed
Operation failed: File /etc/my.cnf doesn't exist
so i've used this option on my terminal
sudo cp my-huge.cnf /etc/my.cn
and it was said
cp: cannot stat 'my-huge.cnf': No such file or directory
when i check my support-files, it was not any single of my.cnf files, so i just confused why my mysql dont have any my.cnf files.
mysql doesn't include .cnf files because the default configuration is reasonably sane.
When my-huge.cnf existed it was written in the year ~2000 and its huge definition didn't change ever. (~4 cpus and ~1G ram - ha, there was even a huge-4G.cnf file for when "huge" wasn't enough)
If something is requiring /etc/my.cnf to exist, create it as an empty file (e.g. touch /etc/my.cnf).

Where does the my.cnf resides on macOS High Sierra?

I wanted to disable some options in the MySql server strict mode, but for some reason I'm not even able to find its configuration file (my.cnf)
Currently installed MySql:
Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64)
Output generated by
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
But there is no such file as my.conf
I had done some research work on SO but none of the advises has worked for me.
What I'm supposed to do?
There are defaults built into MySQL. The configuration file(s), if any, override the defaults.
Note that the config files are not looked at except during startup. So, editing or creating such a file has no effect until you restart mysqld.
If you mess up the syntax, mysqld will not start. Then you need to find the error, either during startup, or in a log file. (Or you could ask here "what is my syntax error".)
As for the location, and name, of the config files that will be used:
$ mysql --help
gives you the list for mysql, but perhaps you need it for the server, so try
$ mysqld --help --verbose
gives you long output; maybe 50 lines from the top, you should see something like:
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
You asked about my.conf; was that a typo?
Regardless, If those files are missing, you can create them, make them readable by mysql, and put things into it preceded by [mysqld] so that the server will see them.
Personal override
Regardless of what is in the defaults and/or config files, you can add to the last file given. In the examples above that is 'hidden' .my.cnf in your home directory. All you need to do is create a few lines:
[mysql]
some_setting = somevalue
[client]
some_setting = somevalue
That helps for the "mysql" commandline tool and/or other clients (maybe).
But if you need to make changes to the server mysqld, it needs to be in one of the other files. Again, the minimum is something like
[mysqld]
some_setting = somevalue
Note the mysqld to refer to the server. And remember to restart the service.
Another note: If you see (in an existing config file), !includedir ..., then go to that directory to find any number of further files. You could add your own file, say z.cnf (so it would be picked last) with the two (or more) lines as indicated above.
If you have installed Mysql 8 or Above using the package installer from mysql website, then follow what i did
Create the config file in your home directory vim ~/.my.cnf
Do open System preferences in mac
Then Select the configuration file you created on the option.
The content in this website says.
I had the urgent need to configure some specific stuff in MySQL 5.7 on my developer machine, a MacBook Pro running Mac OS Sierra. Unfortunately, I did not find a my.cnf file that could be customized anywhere?
Internet research showed that MySQL Database Server on Mac OS runs without a my.cnf config file by default, simply started with default values.
Luckily, it is pretty simple to customize the MySQL Server installation by creating and editing a custom my.cnf file like this:
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
Then edit / customize the /etc/my.cnf file as required and restart your MySQL Server.
Or you can refer to this answer
You could try:
$ locate mysql | grep my.cnf
It should reveal the location(s) if it exists.

Setting `server-id` variable in MySQL doesn't work

I've been trying to set up two databases as master & slave.
I followed the famous guide here:
https://dev.mysql.com/doc/refman/5.1/en/replication-howto-existingdata.html
But no luck on my slave server,
The issue I'm having is setting the server-id variable.
No matter where I define it (I looked into all the possible cnf files that might allow me to define the variable)
I tried to define it like so:
[mysqld]
server-id = 2
I also tried setting it by using SET GLOBAL server_id but obviously, it didn't save the setting.
when I do:
SHOW VARIABLES LIKE 'server_id'
It returns
server_id 0
Among the cnf files I've looked into are:
etc/mysql/mysql.conf.d/mysqld.cnf
etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf
etc/mysql/conf.d/mysql.cnf
etc/mysql/debian.cnf
etc/mysql/mysql.cnf
usr/my.cnf
usr/my-new.cnf
usr/etc/my.cnf
My MySQL server is running on Ubuntu.
And if it matters, I start it by typing:
service mysql start
I'd love to know where else I could look to fix this issue.
Thanks a bunch!
Additional Notes:
MySQL Ignoring the global conf file
I received this warning a couple of times and it disappeared when I returned the chmod to 644 on the etc/mysql folder, although every thing stated above was attempted using both 644 and 777 permissions, with 644 the warning disappears.
I know it's to late, but for those who will make the mistake.
It's server_id and not server-id:
[mysqld]
server_id = 2
For me it worked by renaming the from /etc/mysql/conf.d/my.cnf to /etc/mysql/conf.d/my.ini
I'm not sure of the exact reason for that (feel free to edit this answer and add to it).
I tried out various combinations:
Keeping the variable as: server-id and server_id
Keeping the group/section as: [mysql] and [mysqld]
Renaming the file to: my.cnf , mysqld.cnf, mysql.cnf, my.ini
You can keep trying various combinations out of the above options, it should definitely work. :)

Table is 'read only'

When I want to execute an update query on my table I got an error saying:
1036 - Table data is read only.
How can I fix that?
Table attributes in /var/db/mysql are set to 777.
'Repair Table' function doesnt seems to help.
Is there anything I can do with that?
In my case, mysql config file had innodb_force_recovery = 1. Commenting that out solved the issue. Hope it helps someone.
who owns /var/db/mysql and what group are they in, should be mysql:mysql. you'll also need to restart mysql for changes to take affect
also check that the currently logged in user had GRANT access to update
(This answer is related to the headline, but not to the original question.)
In case you (like me) are trying to temporarily alter data via the MySQL Workbench interface:
If the table does not have a primary key, MySQL Workbench has no way of identifying the row you are trying to alter, so therefore you cannot alter it.
Solution in that case is to either alter the data via another route, or simply to add a primary key to the table.
In any case, I hope it helps someone :)
You should change owner to MYSQL:MYSQL.
Use this command: chown -Rf mysql:mysql /var/lib/mysql/DBNAME
My situation is everytime I needed to edit "innodb_force_recovery = 1" in my.ini to force mysql to start, and the error log showed some error said:
Attempted to open a previously opened tablespace. Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd. Cannot open tablespace profile/profile_commentmeta which uses space ID: 1 at filepath: .\profile\profile_commentmeta.ibd
I didn't know why this file was not able to open and it caused so many other"table read only" problems to other databases too.
So here is how I fixed this problem in a simple way without hurting other files.
1
First of all, make sure if you add innodb_force_recovery = 1
below [mysqld] in my.ini file, and it is working, under path: X:\xampp\mysql\bin\my.ini
2
Then next step, export all the databases through localhost/phpmyadmin under the export tab, and store them somewhere, like this:
3 comment out the data filefolder to data-bak, then create a new data filefolder,
4 Next step, import all .sql database back from phpmyadmin panel, please also copy phpmyadmin filefolder from the old data-bak filefolder to the new data filefolder. If any file is necessary, go back to data-bak filefolder to copy and paste.
Now all fixed and done, don't need to force mysql to start everytime.
Hope this also works for you.
MySQL doesn't have write access to the database file. Check the permissions and the owner of the file.
On windows I use Xampp server I comment the line in my.ini
innodb_force_recovery = 1 to #innodb_force_recovery = 1 the problem resolved
I solved the same issue by editing app. armour configuration file. Found the answer here: https://stackoverflow.com/a/14563327/31755661
maybe you get read only error from your table storage engine.
Check you Storage Engine, maybe if it is MRG_MYISAM change it to MyISAM and try again.
If you are running selinux in enforcing mode then check your /var/log/messages for audit faults. If you see the tell-tale "****" messages about selinux blocking write access to your table files in / then you need to relabel those files so that they have this label:
system_u:object_r:mysqld_db_t:s0
What you could have is a broken label from copying those files over from a user directory (such as during a recovery attempt).
There's a great resource for selinux here:
https://docs.fedoraproject.org/en-US/Fedora/11/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-SELinux_Contexts_Labeling_Files-Persistent_Changes_semanage_fcontext.html
Just remember that you will need to do this for all of those files, which could be many. Then you will want to run the "restorecon -R -v " command to get the recursive (-R) application of the new labels. There is no support for -R in the semanage command, as far as I could tell.
For reference, the semanage command to relabel looks like this:
semanage fcontext -a -t mysqld_db_t 'filename'
The quoting of the file name is critical for the command to work.
In my case there was a table with read-only state set and when I tried to restart mysql service it would not even start again and with no descriptive error.
Solution was to run fsck on the drive (with many fixes), which was advised after Ubuntu reboot.
I'm running Ubuntu in VirtualBox under Windows and it often hangs or is having functionality problems.
One other way to receive this error is to create your table with a "Like" statement and use as source a merged table. That way the newly create table is read-only and can't "receive" any new records.
so
CREATE TABLE ic.icdrs_kw37 LIKE ic.icdrs ... #<- a merged table.
then:
REPLACE INTO ic.icdrs_kw37 ... # -> "Table is read-only"
bug or feature?

MySQL tables on external hard drive

I have a large amount of text data I need to import into MySQL. I'm doing this on a MacBook and don't have enough space for it so I want to store it in an external hard drive (I'm not really concerned about speed at this point - this is just for testing).
What's the best way to do it?
Install MySQL on the external hard drive (is this possible on a Mac?)
Install MySQL on the laptop's hard drive and have the tables on the external (how?)
One simple hack is to create an symbolic link replacing your current mysql database file location pointing to the external disk. Google symbolic link.
sample usage would be after you shutdown mysql, change the old mysql db folder name to something else, and create the symbolic link using the ln command like below
ln -s [EXTERNAL DRIVE PATH] [MYSQL DB FOLDER PATH]
Then move all the previous content of the mysql db folder to the new location.
Open /etc/mysql/my.cnf and find the value of the datadir. Alternatively, you can find this out in the mysql monitor with
mysql> select ##datadir;
Stop mysql
sudo systemctl stop mysql
Copy the data from there to your external drive
sudo rsync -av /var/lib/mysql /mnt/myHDD/somedir/mysql
Modify the location of the datadir in my.cnf.
Start mysql again
sudo systemctl start mysql
Verify that everything is still fine and remove the original data dir.
This page contains a more extensive guide but all the additional issues it warns about were not relevant for me on my raspberry PI. I.e. I skipped them and it worked.
For the second option, a tablespace might do the trick:
http://dev.mysql.com/doc/refman/5.1/en/create-tablespace.html
User user658991 answer is halfway there.
After adding the soft link, you will need to add the following line to /etc/apparmor.d/usr.sbin.mysqld beneath the 2 lines to the old mysql folder.
/path/to/mysql/folder/on/the/external/ r
/path/to/mysql/folder/on/the/external/ ** rwk
Without these 2 lines, MySQL fails to start complaining of:
Can't create test file /path/to/mysql/folder/on/the/external/hostname.lower-test
Can't create test file /path/to/mysql/folder/on/the/external/hostname.lower-test
mysqld: Can't change dir to '/path/to/mysql/folder/on/the/external/' (Errcode: 13)
Restart apparmor for the changes to take effect.
sudo invoke-rc.d apparmor restart
With this, MySQL starts normally.