This is NOT about MySQL's "data directory".
When I log into MySQL on my machine (Windows 10 OS) I know that MySQL still has a "current working directory": importing a .sql file works, giving only the filename, if the file is located in the same directory as the one where I went
> mysql -u ....
So I wondered whether it was possible to get the CWD when actually logged into MySQL. Then I wondered whether it might be possible to change it, i.e. to navigate somewhere else. Then I wondered about running system (i.e. command prompt) commands generally, while still logged in to MySQL.
Here we see a claim that you can indeed do all these things... by going something like:
\! ls -l
On my machine this doesn't work... probably because it's not a Linux OS. I get unknown command '\!'...
Is there any way to do this in Windows?
You're right. The Windows version of the mysql command line client lacks the shell escape \! command.
It is an open source project :-). You or I could give them a pull request with a fix. But then we'd have to decide whether we wanted cmd or powershell in the escaped process.
Related
In mysql5.X database on Linux the command system or ! can be used to run bash command from database command line.
Are there equivalent commands as system or ! in mysql5.X database for Windows?
Linux:
mysql> !ifconig
Windows:
mysql> !ipconfig
The Windows command does not work!
In mysql5.X database (for Linux), command "system" or "!" can be used to run bash command from database command Linux.
You misunderstand.
This is not SQL command. This is command-line client command. And it will work only in CLI or another client which supports this command. It will NOT work if you try to send in to MySQL server directly by any technique.
Is there a equivalent command as "system" or "!" in mysql5.X database (for Windows)?
If used CLI version supports this command then it will work otherwise no. This not depends on MySQL server version.
Windows is not the same operating system, and as such the names of the tools internally are, in many cases, completely different, like ls vs. dir.
ipconfig is a Linux thing but it's also not necessarily a given that it'll be present. On more modern distributions the ip command is becoming the default. That's to say you'll need to lookup what the command you're going to run is, and verify that with testing.
You'll need to run the command appropriate for the environment you're running on, whatever that is.
That being said, running shell commands inside of the mysql> shell is highly irregular and should be a last resort. Doing it can be viewed as highly suspicious and may be restricted.
A while back I installed xampp and could not get it to run because the ports were already being used. Someone recommended that I type .. I believe it was: kill all, into the terminal to, I guess, kill the conflicting connections. This worked and I was able to access phpMyAdmin, but then I started having the problem again so i switched to MAMP. Now I can not access MySQL through the terminal. This is what I type in and this is what I get:
Macintosh:~ scottmcpherson$ mysql -u root --password=This_is_where_I_typed_my_pw
-bash: mysql: command not found
Macintosh:~ scottmcpherson$
I can, however access my database through phpMyAdmin. But the tutorials I'm following only show you how to create a database through the terminal plus I would really like to learn how to do it both ways. So, I'm thinking that the killall command screwed something up, or the other command that someone recommended a while back- which I can't remember.
You need to adjust your PATH environment variable. Details are here: http://www.metaltoad.com/blog/getting-command-line-access-php-and-mysql-running-mamp-osx
In short, open (or create) a .profile file in your home directory, and add this line:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH
Paths may need to be adjusted depending on the location of your MAMP install.
Is there any nice command line MySQL client for windows? I mean a single exe that allows connecting and running a sample query. I've googled and only could find big graphical environments like toad or mysql workbench. I need only a simple command line tool, where can I download sth like this?
EDIT: I don't want to install the whole MySQL package on my PC. I know it's inside the mysql package but how do I download only this cmd line client. Because i don't need anything else.
When you go to the MySQL download page, choose the platform "Microsoft Windows". Then download the "Windows (x86, xx-bit), ZIP Archive" (be sure to select the one with size over 140M.
The binaries will be in the "bin" folder.
I understand that this is not just the client binaries, but at least you don't have to install and setup the entire server.
mysql.exe can do just that....
To connect,
mysql -u root -p (press enter)
It should prompt you to enter root password (u = username, p = password)
Then you can use SQL database commands to do pretty much anything....
You can choose only install the client during server install. The website only offers to let you download the full installer (grab whatever version you want from http://www.mysql.com/downloads/mysql/).
In the install wizard, when prompted for installation type (typical, minimal, custom), choose 'Custom'. On the next screen, select to NOT install the server, and proceed with the rest of the install as normal.
When you're done, you should see just the relevant client programs (mysql, mysqldump, etc) in C:\Program Files\MySQL..\bin
Its pretty simple. I saved the mysql community server in my D:\ drive. Hence this is how i did it.
Goto D:\mysql-5.7.18-winx64\bin and in the address bar type cmd and press enter, so command prompt will open. Now if you're using it for the first time type as mysql -u root -ppress enter. Then it will ask for password, again press enter. Thats it you are connected to the mysql server.
Before this make sure wamp or xampp any of the local server is running because i couldn't able to connect to mysql wihthout xampp running.
Happy Coding.
You can also download MySql workbench (31Mo) which includes mysql.exe and mysqldump.exe.
I successfully tested this when i had to run Perl scripts using DBD:MySql module to run SQL statements against a distant MySql db.
You can access mySQL in command line just by typing:
C:\www\mysql\bin> mysql -u root -p
After which you can type sql commands normally such as:
mysql> SHOW DATABASES;
Here, I am assuming you mySQL installation directory is C:\www\mysql.
I have similar requirement where I need a MySQL client but not server (running in a virtual machine and don't want any additional overhead) and for me the easiest thing was to install MySQL community server taking typical installation options but NOT configure the server, so it never starts, never runs. Added C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin to system path environment variable and I'm able to use the MySQL command line client mssql.exe and mysqladmin.exe programs.
If you are looking for tools like the the mysql and mysqldump command line client for Windows for versions around mysql Ver 14.14 Distrib 5.6.13, for Win32 (x86) it seems to be in HOMEDRIVE:\Program Files (x86)\MySQL\MySQL Workbench version
This directory is also not placed in the path by default so you will need to add it to your PATH environment variable before you can easily run it from the command prompt.
Also, there is a mysql utilities console but it does not work for my needs. Below is a list of the capabilities on the mysql utilities console in case it works for you:
Utility Description
---------------- ---------------------------------------------------------
mysqlauditadmin audit log maintenance utility
mysqlauditgrep audit log search utility
mysqldbcompare compare databases for consistency
mysqldbcopy copy databases from one server to another
mysqldbexport export metadata and data from databases
mysqldbimport import metadata and data from files
mysqldiff compare object definitions among objects where the
difference is how db1.obj1 differs from db2.obj2
mysqldiskusage show disk usage for databases
mysqlfailover automatic replication health monitoring and failover
mysqlfrm show CREATE TABLE from .frm files
mysqlindexcheck check for duplicate or redundant indexes
mysqlmetagrep search metadata
mysqlprocgrep search process information
mysqlreplicate establish replication with a master
mysqlrpladmin administration utility for MySQL replication
mysqlrplcheck check replication
mysqlrplshow show slaves attached to a master
mysqlserverclone start another instance of a running server
mysqlserverinfo show server information
mysqluserclone clone a MySQL user account to one or more new users
mysql.exe is included in mysql package. You don't have to install anything additionally.
download the mysql-5.0.23-win32.zip (this is the smallest possible one) from archived versions in mysql.com website
cut and paste the installation in c drive as mysql folder
then install then follow instructions as per this page:
https://cyleft.wordpress.com/2008/07/20/fixing-mysql-service-could-not-start-1067-errors/
For Windows users:
1.Install the full version of MYSQL
2.On the Windows 10 start button click on search and type in MySQL
3. Select the MYSQL Command Line Client 5.5 (I am using version 5.5)
4. go ahead and run your sql queries/
5. to exit type \q or quit
Hi I'm logging slow queries because we're having some performance
issues and I have read about mysqldumpslow and thought that would be a good
way to sort through the queries.
At the command prompt, I type mysqldumpslow and I get this:
'mysqldumpslow' is not recognized as
an internal or external command,
operable program or batch file.
I'm using MySQL version 5.0.79 on Windows Vista.
Note:
c:\Program Files\MySQL\MySQL Server 5.0\bin is my path and I have searched the drive for 'mysqldumpslow' and can not find it.
What am I doing wrong?
Note:
MySql 5.0.x does support the mysqldumpslow command follow this link to manual
edit : oops, I read the manual wrong, and gave wrong information :-( sorry :-( let's give it another try...
I've just installed MySQL on windows, to try using mysqldumpslow, and I don't have mysqldumpslow installed either :-( So, you are not alone, and it doesn't seem to be a problem with your install (I've tried 5.1.x, but as you highlighted, it should be the same for 5.0.x)
Looking at the "mysqldumpslow" I have under Linux, it appears it is a Perl script ; and Perl is not often installed on a Windows machine. Maybe that would be a hint to a solution...
Well, after a bit more testing, when installing MySQL, it seems you have to select "Developpers Components > Scripts, examples", which is not installed by default (at least on windows) -- no need to reinstall everything : you can "modify" the installation, to add this option.
Then, you will have a "script" directory next to the "bin" one.
For instance, on your install, it should be something like "c:\Program Files\MySQL\MySQL Server 5.0\scripts".
In this directory, there are some scripts ; one of them is mysqldumpslow.pl ; which is what you are looking for ;-)
Now, you "just" have to get Perl installed and running on your machine (sorry, I've never installed Perl on windows ; but you can find some informations here)
Hope this helps better than what I posted before !
try typing
whereis mysqldumpslow
If that still says its not installed,
EDIT: Above is not relevant, as on windows. Missed that, thanks to commenter for pointing it out.
I always use mysqlsla (mysql slow log analyser) ahead of mysqldumpslow - you could give that a go.
http://hackmysql.com/mysqlsla
Mysqldumpslow is a Perl script so under Windows you will need to make
sure you have Perl installed and will need to explicitly invoke it via
Perl.
The way the script is set up it will work automatically under Unix
because Unix has the ability to run scripts directly by identifying the
correct script processor from the first line of the script. Of course
you still need Perl installed, but that is taken for granted in most
Unix installations.
Or you can also try to set the path in Windows environment variables.
In oracle database, command "host" can be used to run bash command from database command window. Is there a equivalent command as "host" in mySql?
You can use the system command.
system command, \! command
Executes the given command using your
default command interpreter.
The system command works only in Unix.
Example:
system ls -l
As an additional tweak, on most "'nix" systems you can actually do something like this:
mysql> system bash
And have the entire terminal at your disposal. This is particularly effective if you're doing code work in the terminal that interfaces with MySQL; from the shell, typing "exit" will take you back into the MySQL monitor/client, so you can go back and forth quite easily.
Obviously, other shells ("mysql> system tcsh") would work as well.
It's actually possible to execute shell commands on the server that mysqld is running though a client connection (rather than executing commands on the client machine locally) by using MySQL Proxy (scroll down to the "Shell commands from MySQL client" section ).
I'm running version 5.0.95-log on Linux. Prefacing the command either by "system" or by "!" works for the "pwd" and the "ls -l" commands. If I try to change directory using, e.g.
mysql> system cd /home/mydir
the command seems to be accepted. But this apparently does nothing, as following "pwd" and "ls -l" commands indicate that I am still in the same directory. So it appears that there is a stub of limited functionality built in for this, but that we do not actually have full access to the system shell.
In a linux machine you should be able to use the following example
! clear - to clear the screen
! ls - to list files in the current working directory
Basically you should be able to run any command or script using that syntax
NB: Add a back slash before !