In Linux, and many other systems, when navigating the terminal you can press Tab to auto complete a directory or file name.
I'm wondering if there is anything like that in the MySQL terminal. For example, if I want to get the description of someTableWithRidiculousLongName I could type describe someTableW then Tab and it would auto-complete the rest.
Does anything like that exist in the MySQL terminal?
Edit or create a file called .my.cnf in your home directory, containing:
[mysql]
auto-rehash
To enable autocomplete within the MySQL prompt type:
mysql> \#
After that you can type:
mysql> describe someTableW[TAB]
To get:
mysql> describe someTableWithRidiculousLongName
start MySQL console with additional option --auto-rehash, i.e.
mysql --auto-rehash -u root -p
I know this is an old question, but I've found very helpful MySql cli client with advanced autocompletion:
mycli. It's much smarter than builtin auto-rehash feature.
On OS X 10.11.6 I set --auto-rehash as described above, but it did not work. (This is OS X so mysql is compiled with the BSD libedit library.)
Then I remembered that I had set vi key-bindings for mysql client by creating ~/.editrc, containing one line: bind -v. This works great for giving me vi-like navigation in mysql client, but it broke column name completion (I was able to verify this by removing .editrc).
So I researched a little bit and found that ~/.editrc should have at least the following lines:
bind -v
bind \\t rl_complete
With this additional line, name completion works correctly in mysql AND vi-like navigation works also. (There are other .editrc settings which greatly improve mysql client navigation, but this isn't the place to start that thread of discussion.)
Some notes about auto-rehash:
When you enable autocompletion editing the mysql config file..
[mysql]
auto-rehash
You can do it for all users or only for one user:
/etc/my.cnf: All Users
~/.my.cnf: Actual user
You can also disable autocompletion adding:
no-auto-rehash
Extracted from: http://www.sysadmit.com/2016/08/linux-mysql-autocompletar.html
You can also auto-complete based on the command history. Start typing, then invoke the keys which are bound to ed-search-prev-history and ed-search-next-history. This applies if mysql comes with libedit support. The default keybindings are Ctrl-P and Ctrl-N, but this can be customized in .editrc. My example for Ctrl-up and Ctrl-down:
# start typing, then press Ctrl-Up
bind "\e[1;5A" ed-search-prev-history
# start typing, then press Ctrl-Up, then Ctrl-Down
bind "\e[1;5B" ed-search-next-history
Previously, mysql was based on readline, and then history-search-backward and history-search-forward are the correct commands. Configuration then was by means of .inputrc. Same example as above:
# these are the key bindings for the readline library
# start typing, then press Ctrl-Up
"\e[1;5A": history-search-backward
# start typing, then press Ctrl-Up, then Ctrl-Down
"\e[1;5B": history-search-forward
So, say you started typing sel and invoke Ctrl-Up, select * from some_long_table_name would come up if that is a command I have used earlier.
Related
I have the following question. I want to build a Centos 7 imagine using Packer. I want to run the template without a kickstart file .cfg due to some security issues. Is it possible to write all the commands from the kick start file to the template.json?
This is how it actually looks:
"boot_command": "<tab> inst.text inst.ks=https://raw.githubusercontent.com/xxx/xxx/xxx/centos-7.cfg <enter><wait>",
# Turning on text-mode installation (little quicker than GUI)
text
# Setting up authentication and keyboard
auth --enableshadow --passalgo=sha512
keyboard --vckeymap=us --xlayouts='us'
# Installation files source (CentOS-7.0-1406-x86_64-Minimal.iso)
cdrom
# Using only primary disk, ignoring others
ignoredisk --only-use=sda
# Setting up language to English
lang en-US.UTF-8
...
And I want something like:
text
auth --enableshadow --passalgo=sha512
keyboard --vckeymap=us --xlayouts='us'
cdrom
ignoredisk --only-use=sda
lang en-US.UTF-8"
...
Unfortunately, the virtual machine doesn't realize that I am sending these commands as kickstart commands and it starts in the GUI mode.
How is your source built?
You will need to create a boot command directive that simulates the keys so that it can start and make the ks file available for the installation (using floppy_dirs or similar)
Location of MySQL configuration file (ie: my.cnf) not specified
How can I fixed this thing?
I been trying to reinstall mysqlserver 5.5 / 5.7 and workbench countless of time. But I still not able to fix this issue.
I solved this problem. Step one: click here
Step two: and then click here to choose your path
Step three: my path is C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
If you already know where your configuration file is located, but just don't know how to specify it in mySQLWorkbench, you can skip steps 1-3 and just follow step 4 in these instructions.
Step 1: Make sure which mysql is running (just in case you have multiple installations on your system) and how:
$ ps aux | grep mysql
may result in something like:
_mysql 120 0,0 3,4 5122736 565108 ?? Ss Fr01pm 61:05.93 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
If, in this output, you see that mysqld has been started with the --defaults-file option, that option specifies the configuration file used by msql. If so, you have found the configuration file and can skip to step 4.
If not, check if this returns the same binary location as above command:
$ which mysqld
If not, then make sure you use the full path for mysqld from the first output in the following step.
Step 2: Ask mySQL which configuration files it is using:
$ mysqld --verbose --help | grep -A 1 "Default options"
should output something like:
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
Step 3: Check the given locations in that order. The first finding should be your mySQL configuration file.
Step 4: In mySQLWorkbench go to Database > Manage Connections, then select the connection, select tab System Profile, and enter the path and file name in Configuration File.
This should be it.
And if still nothing happens, you may have used the installer Package. If you have, then you must select the Installation Type from the drop-down to reflect that before you locate the configuration file.
Here's a screenshot that follows from the above screenshots
Also, there may not be a config file and you can create one here, then get out of the Options File, go back in and you will see all the options.
I changed my setting from Custom to MacOSx (MySQL Package) under: Database → Manage Connections → MySQL Connections → Select DB Connection → System Profile → Installation Type → (default setting) MySQL Package.
Change from custom to default setting:
Reconnect by testing connection:
For maria-db users
back up the original /etc/mysql/my.cnf
copy and rename /etc/mysql/mariadb.conf.d/50-server.cnf to /etc/mysql/my.cnf.
This would fix the problem.
Remember to revert changes after finish.
For those with Mac OS Catalina:
I did not have a my.cnf file. I went to /usr/local/mysql/
and created a directory named etc, which I did not have either.
Then, inside that directory, I created the file (my.cnf).
This is the link that helped me How to fix --secure-file-priv option error
for mysql 5.7 users and MAMP: just create /etc/my.cnf
macOS 13 and MySQL 8 current:
Open MySQL Workbench on your Mac. Connect into your localhost instance of MySQL.
Click the little wrench icon next to INSTANCE on the left pane above Startup / Shutdown.
Select macOS as System Type, macOS as Installation Type, and the rest will default into place. Copy the location it gives you for the my.cnf file.
Click Close
Now click Options File on the left. It will notice that you don't have a file and will show you default values.
Click the Apply... in the bottom right corner.
It will then ask you for a password of your current logged in user of your Mac to create and save the my.cnf file.
Now in the Finder use the keyboard combo of Command-Shift-G and copy in your location we copied early (i.e. /etc/my.cnf)
It's no full support and not flexible(WORKBENCH), still no solution....
I want to create dump scripts of each table in my database....
workbench 5.2.47 CE version i am using...
I checked
My database and all tables
And options like dump stored routines, dump events
in advanced options i checked.......
add-locks,
complete-insert,
replace,
hex-blob,
disable-keys,
order-by-primary,
create-options,
allow-keywords,
quote-names
Problems.
How I save the configuration setting or all above setting I did..and second time I want to add just my setting file if I save.. And create a dump
CREATE DATABASE IF NOT EXISTS mydatabase /*!40100 DEFAULT CHARACTER SET latin1 */;
USE mydatabase;
..................This one I want to skip or exclude form dump scripts but there are no options in workbench as in mysql command is there --no-create-db, -n and for remove USE mydatabase remove option as --databases
All mysqldump options are not available which I need.............
Any solution for above questions or any custom create options in workbench...
Thanks..
I have just met similar problems and found the following way to add options.
My environment is:
Windows 8/64bit
MySQL Workbench 6.08
(you may adjust the step according to your system such as Linux)
First, close MySQL Workbench
In the folder:
C:\Program Files (x86)\MySQL\MySQL Workbench CE 6.0.8\modules
there are many python files, there is a file called
wb_admin_export_options.py which is Python source code and there is
another file with same name
wb_admin_export_options.pyc which is a compiled Python file.
Step to Edit
rename 2 into wb_admin_export_options.pyc-org to avoid the program
read the old option list and make a copy of 1 in case there is any
problem
run your code editor in Administrator mode if in Window for UAC reason.
Open wb_admin_export_options.py
Note: You will see the option list for mysqldump which is appear in
Workbench->Administration[Tab]->Advanced Options...[button on the top right]
Note on editing the file
Add the option you need in the list similar to the source code, eg:
The true of false near the closing bracket means default value (check or uncheck by default)
"create-options":["Include all MySQL-specific table options in CREATE TABLE statements.","TRUE"],
Open the MySQL Workbench again and it will read the updated option list and let you choose from.
Hope this help.
I am trying to build an msi that will upgrade an installation of mysql.
I can perform the basic upgrade of files and on a clean install everything works fine, the problem I have is, when performing an upgrade I need to perform a couple of actions around the uninstall of the previous version.
The only action I'm having trouble with is a change of one of the MySQL GLOBAL settings using the following command line
mysql.exe -u root --host=127.0.0.1 --port=5002 mysql --execute="SET GLOBAL innodb_fast_shutdown=0"
I do this as it is suggested that when upgrading a database innodb should perform a slow shutdown and this was the easiest way I could see of doing this.
Currently I use the following Wix to perform this action
<CustomAction Id="Innodb_slowshutdown" Property="OLDMYSQLEXE" Execute="immediate"
ExeCommand=""[MYSQLINSTALLBINPATH]mysql.exe" -u root --host=127.0.0.1 --port=5002 mysql --execute="SET GLOBAL innodb_fast_shutdown=0""
Return="check" Impersonate="yes"/>
...
<Custom Action="Innodb_slowshutdown" After="InstallInitialize">UPGRADEFOUND and NOT UPGRADINGPRODUCTCODE and NOT REINSTALL and MYSQLINSTALLBINPATH</Custom>
<RemoveExistingProducts After="Innodb_slowshutdown" />
However this always fails and I cannot understand why as when the fail occurs I copy the exact command line from the msiexec log and run it through a command line.
This works exactly as I would expect but I cannot figure out what the custom action is doing that is different.
During the install a console opens briefly and it would seem that the MySQL executable runs but something is wrong with the arguments and it causes a load of help info to come up, though I cant be sure this is exactly whats happening as it passes very quick.
Is there any way to pause the install at this point so I can see what is in the console?
Can anyone see any obvious problems with my Wix?
EDIT -
Also I'm not sure if this has anything to do with user rights, I run MSIEXEC from a command prompt opened "As Administrator" but if I did need to elevate rights how could I do this when I need to execute the action with the type immediate?
Please note I am aware that Immediate does not allow elevated rights but I cannot use deferred as it will not allow me to execute the command before RemoveExistingProducts.
I am not even sure it is anything to do with rights, I am merely pointing out that I have considered this as a possible reason but I cannot prove it.
Windows Installer doesn't support immediate custom actions that run with elevated rights. To execute a custom action with elevated rights, it must be marked Deferred="yes" and Impersonate="no".
Ok I found my mistake, this was due to not knowing how a Type 50 CaustomAction works.
All I had to do was to use a Property that contained the full path of the executable I wanted to execute and use ONLY command line arguments in the ExecuteCmd property
<CustomAction Id="Innodb_slowshutdown" Property="OLDMYSQLEXE" Execute="immediate"
ExeCommand="-u root --host=127.0.0.1 --port=5002 mysql --execute="SET GLOBAL innodb_fast_shutdown=0""
Return="check" Impersonate="yes"/>
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?