我想将MySQL变量innodb_autoinc_lock_mode从默认值1更改为0,因为它会导致使用INSERT IGNORE等进行查询的应用程序中自动增加ID空白的问题。
我知道可以通过添加设置来更改所有服务器:
innodb_autoinc_lock_mode=0
内部文件:
/etc/my.cnf
但有可能对每个用户执行此操作,例如在php.ini文件中,在cPanel / WHM共享主机帐户上执行此操作???
我尝试使用变量和值设置文件:
/home/username/.my.cnf
/home/username/my.cnf
/home/username/etc/.my.cnf
/home/username/etc/my.cnf
通过设置每个用户的文件或通过phpMyAdmin等,它们似乎都不起作用,有什么想法可以做到这一点吗?
谢谢!
答案 0 :(得分:0)
innodb_autoinc_lock_mode
system variable是一个全局(非会话)变量,在运行时是只读的。
在任何情况下,同一个MySQL服务器的多个连接都不可能为此变量赋予不同的值。
此外,我不确定将此值设置为0是否与import java.awt.AWTException;
import java.awt.EventQueue;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
public TestPane() {
BarCodeLengthDocumentListener lengthListener = new BarCodeLengthDocumentListener(7, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = e.getActionCommand();
JOptionPane.showMessageDialog(TestPane.this, text);
}
});
DelayedDocumentListener delayedListener = new DelayedDocumentListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = e.getActionCommand();
JOptionPane.showMessageDialog(TestPane.this, text);
}
});
JTextField field1 = new JTextField(7);
field1.getDocument().addDocumentListener(lengthListener);
JTextField field2 = new JTextField(7);
field2.getDocument().addDocumentListener(delayedListener);
add(field1);
add(field2);
JButton simLength = new JButton("Simulate Length");
simLength.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
field1.setText(null);
field1.requestFocusInWindow();
Thread t = new Thread(new Simulator());
t.start();
}
});
JButton simDelay = new JButton("Simulate Delay");
simDelay.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
field2.setText(null);
field2.requestFocusInWindow();
Thread t = new Thread(new Simulator());
t.start();
}
});
add(simLength);
add(simDelay);
}
}
public class Simulator implements Runnable {
@Override
public void run() {
try {
Robot bot = new Robot();
type(KeyEvent.VK_1, bot);
type(KeyEvent.VK_2, bot);
type(KeyEvent.VK_3, bot);
type(KeyEvent.VK_4, bot);
type(KeyEvent.VK_5, bot);
type(KeyEvent.VK_6, bot);
type(KeyEvent.VK_7, bot);
} catch (AWTException ex) {
ex.printStackTrace();
}
}
protected void type(int keyStoke, Robot bot) {
bot.keyPress(keyStoke);
bot.keyRelease(keyStoke);
}
}
public class BarCodeLengthDocumentListener implements DocumentListener {
private ActionListener actionListener;
private int barCodeLength;
public BarCodeLengthDocumentListener(int barCodeLength, ActionListener actionListener) {
this.actionListener = actionListener;
this.barCodeLength = barCodeLength;
}
@Override
public void insertUpdate(DocumentEvent e) {
doCheck(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
doCheck(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
doCheck(e);
}
protected void doCheck(DocumentEvent e) {
Document doc = e.getDocument();
if (doc.getLength() >= barCodeLength) {
try {
String text = doc.getText(0, doc.getLength());
ActionEvent evt = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, text);
actionListener.actionPerformed(evt);
} catch (BadLocationException exp) {
exp.printStackTrace();
ActionEvent evt = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);
actionListener.actionPerformed(evt);
}
}
}
}
public class DelayedDocumentListener implements DocumentListener {
private ActionListener actionListener;
private String text;
private Timer timer;
public DelayedDocumentListener(ActionListener actionListener) {
this.actionListener = actionListener;
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ActionEvent evt = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, text);
actionListener.actionPerformed(evt);
}
});
timer.setRepeats(false);
}
@Override
public void insertUpdate(DocumentEvent e) {
doCheck(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
doCheck(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
doCheck(e);
}
protected void doCheck(DocumentEvent e) {
try {
Document doc = e.getDocument();
text = doc.getText(0, doc.getLength());
} catch (BadLocationException ex) {
ex.printStackTrace();
}
timer.restart();
}
}
}
语句相关。如果它确实避免了分配但不需要的丢失值,那么文档在这一点上非常不清楚。