I am tring to use this to install mysql from the command line
cls
echo off
SET ProgFiles86Root="%ProgramFiles(x86)%"
IF NOT %ProgFiles86Root%=="" ( SET ProgFiles86Root=%ProgramFiles% )
echo Starting MySQL install
msiexec /i "mysql-5.5.11-win32.msi" /qn
echo MySQL installed successfully
echo Configurating MySQL Server...
"%ProgFiles86Root%\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe" -i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER
DatabaseType=MIXED Port=3306 Charset=utf8
echo MySQL has been installed successfully
setx PATH "%%ProgFiles86Root%\MySQL\MySQL Server 5.5\bin%;"
cd /
c:
mysql --user=root --password=mysql -e "CREATE USER 'myuser'#'localhost' IDENTIFIED BY '123456';"
mysql --user=root --password=mysql -e "GRANT ALL ON mydatabase.* TO 'myuser'#'192.168.0.%' IDENTIFIED BY '123abc' WITH GRANT OPTION; FLUSH
PRIVILEGES;
But i get the error
Starting MySQL install
MySQL installed successfully
Configurating MySQL Server...
The system cannot find the path specified.
MySQL has been installed successfully
SUCCESS: Specified value was saved.
'mysql' is not recognized as an internal or external command,
operable program or batch file.
'mysql' is not recognized as an internal or external command,
operable program or batch file.
The command line says Mysql was installed, but it wasnt, as i cannot fined it in the uninstall section in control panel
Mistake 1: Assigning program files folder path with and without double quotes to ProgFiles86Root
This line
SET ProgFiles86Root="%ProgramFiles(x86)%"
assigns the string "%ProgramFiles(x86)%" with the double quotes and all possibly existing trailing spaces and tabs to environment variable ProgFiles86Root.
The IF condition in line
IF NOT %ProgFiles86Root%=="" ( SET ProgFiles86Root=%ProgramFiles% )
works because the value of the environment variable ProgFiles86Root is with double quotes. The double quotes are also compared by command IF, not just the strings enclosed by the double quotes.
But if this IF condition is true because of batch file is running on a 32-bit Windows, the value of environment variable ProgramFiles is assigned to the environment variable ProgFiles86Root without double quotes.
For more details on how to assign a string correct to an environment variable see the answer on How to set environment variables with spaces? and also the answers linked there.
Let us next look on:
"%ProgFiles86Root%\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe"
This is either expanded for example on 64-bit Windows to
""C:\Program Files (x86)"\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe"
with double quotes inside a double quoted file name with path which is of course not good, or for example on 32-bit Windows to
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe"
which would be a correct specification of the executable.
Mistake 2: Invalid command line in batch file
The next mistake is on line:
DatabaseType=MIXED Port=3306 Charset=utf8
This line does not contain a command to execute for Windows command interpreter and therefore must result in an error message.
I'm quite sure that this line contains options for the mysqlinstanceconfig.exe command line. The same mistake is made on last line of batch code in question with the string PRIVILEGES; which should be at end of the command line above.
Mistake 3: Attempt to REPLACE user PATH with a custom folder path
The command setx is for REPLACING user (as done here) or system PATH (only with option /m which of course requires administrator privileges) and does not have any effect on local PATH of currently running command process interpreting the commands in the batch file.
It is of course a very bad idea to REPLACE the user PATH by the string you specified on the setx command line although there is by default no user PATH defined. This computer could start not working anymore as expected if this attempt to replace the user path would be successful.
It looks like you want to just append the path to directory bin of MySQL Server 5.5 to local PATH to run the executable mysql without path. But why not running mysql.exe with full path?
Mistake 4: Setting a different current directory is done wrong
cd /
c:
The first line does nothing. To set current directory to root of current drive it would be necessary to run cd \ as the backslash character is the directory separator on Windows and the forward slash is for options. The command CD interprets the slash as beginning of an option and therefore ignores it as there is no option specified after the forward slash. Run in a command prompt window cd /? for help on this command.
The second line makes the current directory on drive C: the current directory for the currently running command process. Which directory is the current directory on drive C: is not defined by this code.
Mistake 5: Attempt to run mysql.exe without path and file extension
The command setx hopefully for all users failed although this is very unlikely. But even if setx is successful, the current command process interpreting the batch file has already its local copy of all environment variables from parent process created on starting the batch file. Therefore running mysql without file extension and path must fail, except MySQL was already installed before and its directory bin was already added to system or user PATH before the batch file processing started.
Solution:
Use this batch code:
#echo off
cls
if "%ProgramFiles(x86)%" == "" (
set "MySQLServerPath=%ProgramFiles%\MySQL\MySQL Server 5.5\bin"
) else (
set "MySQLServerPath=%ProgramFiles(x86)%\MySQL\MySQL Server 5.5\bin"
)
echo Starting MySQL install ...
%SystemRoot%\System32\msiexec.exe /i "mysql-5.5.11-win32.msi" /qn
echo MySQL installed successfully.
echo Configurating MySQL Server ...
"%MySQLServerPath%\mysqlinstanceconfig.exe" -i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER DatabaseType=MIXED Port=3306 Charset=utf8
echo MySQL has been configured successfully.
cd /D C:\
rem if not "%PATH:~-1%" == ";" set "PATH=%PATH%;"
rem set "PATH=%PATH%%MySQLServerPath%"
"MySQLServerPath\mysql.exe" --user=root --password=mysql -e "CREATE USER 'myuser'#'localhost' IDENTIFIED BY '123456';"
"MySQLServerPath\mysql.exe" --user=root --password=mysql -e "GRANT ALL ON mydatabase.* TO 'myuser'#'192.168.0.%' IDENTIFIED BY '123abc' WITH GRANT OPTION; FLUSH PRIVILEGES;"
The path to directory for MySQL binaries is not added to system PATH by this batch code if not done on installation or configuration of MySQL. If for some unknown reason the local PATH must be extended with path to MySQL binaries directory, uncomment the two lines near end of batch file above by removing the command REM from both lines.
But if you really want to add MySQL binaries directory to user or system PATH which I really don't recommend then read very carefully the comments and answers on
Why are other folder paths also added to system PATH with SetX and not only the specified folder path?
How can I use a .bat file to remove specific tokens from the PATH environment variable?
How to check if directory exists in %PATH%?
Related
I've recently upgrade a server to Debian 9 and MySQL to the latest version. I have a simple backup script that I run before performing any work on a production site but this time, when running my script, I encounter the following:
mysqldump: unknown variable 'local-infile=0'
Here is my script. What's going on?
#!/bin/bash
# [skipping commentary]
SITE=prod
# Set the directory that the Drupal root is IN, no trailing slashes
DROOT=[website_root]
# Set the directory for storing backups, no trailing slashes
BUD=/$DROOT/notes/backups
# Don't edit; End of defining variables
echo Doing a full back up...
echo Prepare to enter MySQL password...
# tar -czf $BUD/$SITE-files-$(date +'%Y%m%d%H%M%S').tgz $DROOT/docroot
mysqldump -u mysql_user -p drupal > $BUD/$SITE-drupal-$(date +'%Y%m%d%H%M%S').sql
mysqldump -u mysql_user -p civicrm > $BUD/$SITE-civicrm-$(date +'%Y%m%d%H%M%S').sql
ls -lh $BUD
pwd
echo Finished with backups...
MySQL version 10.1.37-MariaDB-0+deb9u1 Debian 9.6
Edit: When I ssh and run mysqldump with correct permissions I get the same issue. Weirdest thing, cron that runs similar process is backing up my databases as ordered.
The best way to solve this is simply to rename the variable to:
loose-local-infile=1
This will allow mysqldump to merely throw a warning, rather than a fatal error.
The suggestion to comment out the variable is not an option if you want LOAD DATA INFILE functionality out of the box, and MySQL 8+ for security reasons requires you to set this variable for both server (mysqld) and client. It is the [client] variable grouping in your config that chokes mysqldump if you don't add the "loose-" prefix to local-infile.
Seems like the new version you install is compiled without support of local-infile parameter. And because package management system (usually) keep your current configuration file you can try to find this parameter in my.ini file and comment it.
This parameter manage LOAD DATA LOCAL functionality. But seems like this have some potential security issues (more here)
I have installed WampServer Version 2.5 on my computer. I have been trying to set the MySQL root password using command prompt but it will not recognize my commands.
When I type the following:
mysqladmin -u root status
I get the following error:
'mysqladmin' is not recognized as an internal or external command, operable program or batch file.
I was following online directions, in order to add the MySQL command prompt in WampServer to my Windows system path, and I think I did it right.
I also did a command line search for the 'mysqld.exe' file using
'dir mysqld.exe /s /p'
and I did not get any directory path.
You should navigate in command prompt to the folder where is mysqladmin file. Try to find it with Find interface in Windows. Then try to mysqladmin -u root status or whatever you need.
Then you can add it's path to system variables, so it could be reached from every folder in command prompt.
You can add a password to the root through mysqladmin.exe.
This executable is usually inside <wamp path>\bin\mysql\mysqlx.x.x\bin
Call the executable with the following parameters.
mysqladmin -u root password rootpassword
I installed MySql 4.1(because that what is running on my server), I got a file that is a dump of my database. It is about 4.6 GB.
I put that file in same location as MySql.exe lives C:\Program Files\MySQL\MySQL Server 4.1\bin
Then I go to command line and type in:
mysql -h localhost -u root -p [database name] < mysqlDump.sql
I get message back 'The system cannot find the file specified.'
What file is it referring to? The mysqlDump.sql?
Even when I specify the full path to the mySqlDump.sql file, I get the same message.
mysql -h localhost -u root -p [database name] < C:\Program Files\MySQL\MySQL Server 4.1\bin\mysqlDump.sql
I'm running MySql 4.1 on Windows7
update found out my mistake. My folder was hiding file extensions. Somehow when I saved the file on my machine I gave it an extra .sql extension. So the file had a name of mysqlDump.sql.sql
You are probably not in the right directory when you make the call.
Go there:
cd "C:\Program Files\MySQL\MySQL Server 4.1\bin"
or specify the input file's absolute path:
mysql -h localhost -u root -p [database name] < "C:\Program Files\MySQL\MySQL Server 4.1\bin"
Use TAB key when you are starting typing mysqlDump... to ensure that your file is there and you have privileges for it.
Tab key in command line will complete filename or not.
This will give you some information if the file exists and if you have permissions to that file. Maybe it was created from other operating system user account and you have no read privileges.
I put that file in same location as MySql.exe lives C:\Program
Files\MySQL\MySQL Server 4.1\bin
This is not good idea, because regular operating system user accoung may have no privileges to write in Program Files directory.
To do it properly I would add C:\Program Files\MySQL\MySQL Server 4.1\bin to the PATH environment variable (link with howto). After you do this you will be able to run MySQL executable files from anywhere you want (like your desktop or documents folder for example) without messing around in Program Files. You can place your working file at location where you have all privileges and work on it from the command line.
I am trying to reset the root password for mySQL Workbench since I forgot it. I was reviewing some online tutorials of how to do this, and they all speak of a "bin" folder. I went to the program folder, and didn't see a bin folder. How do I do this?
Reset MySQL Root Password from PowerShell
1. Stop the MySQL service and process.
spsv mysql*
kill -f -Pro mysqld -ErrorA Ignore
2. Create a temporary init file
ri C:\temp.txt
ni -t f C:\temp.txt
ac C:\temp.txt "UPDATE mysql.user SET Password=PASSWORD('4321') WHERE User='root';"
ac C:\temp.txt "FLUSH PRIVILEGES;"
3. Get the location of the MySQL defaults-file.
$defaultsFile = (gci -r -Path "C:\ProgramData\MySQL" -include my.ini).FullName
4. Change dir to MySQL bin.
cd "C:\Program Files\MySQL\MySQL Server*\bin"
5. Run mysqld with the password reset.
& .\mysqld.exe --defaults-file="$defaultsFile" --init-file="C:\\temp.txt"
6. Kill and Restart MySQLD (in a new PowerShell prompt).
ps mysqld | kill -f
sasv "MySql*"
7. Return to the initial prompt and test
& .\mysql -u root -p4321
\q
Notes
We cannot do anything until we stop MySql completely.
Create this in C:\, then add reset password commands; ri removes any existing temp.txt file.
You can retrieve this path through the Service Control Manager or use (gwmi win32_service | ?{$_.Name -like 'mysql*'} | select -First 1).PathName.
The * in the path means that we don't have to know our version number.
The & makes PowerShell run the exe like the command line does. Once you run this, PowerShell will appear to hang - that's because it's running the mysqld process.
We need to kill in another process, because the existing console is busy.
Return to the initial console, because it's already at bin. After the test, you should see mysql>. Use \q to quit.
See Also
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
Reset MySQL root password official documentation has cases for Windows and Unix systems, and a "generic" instruction at the end of the document. Hope that helps.
Hey if you are on Windows 7 like me you will find the MySQL executables here: C:\Program Files\MySQL\MySQL Server 5.5\bin . I used mysqld.exe, because mysqld-nt.exe doesn't exist anymore in newer versions of MySQL.
After following the instructions in the documentation you should have a command similar to this:
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld.exe --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my-medium.ini" --init-file=C:\mysql-initRootPass.txt
Note: make sure you run the CMD.exe as Administrator. For the most part that fixed it for me.
Hi I have installed MySQL from oracle website, but did not get a "MySQL Command Line" option under MySQL in Programs menu.
So I looked up on this site how to execute sql queries from DOS command prompt.
I found an answer on this site that advised to type in something like: sql root u- p- etc. but this does not work.
Can anyone advise me the syntax to use to go into sql from DOS, or direct me to the answer described above (I cannot locate it)
I use Windows 7 and downloaded the ODBC driver, too.
Many thanks.
Unless MySQL's bin directory is in your PATH variable, you will need to either be in the directory, or write an absolute path to it to execute.
Try something like this (depending on your installation):
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -uroot
Alternatively, you could type this directly:
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" -uroot
cd/
cd wamp
cd bin
cd mysql
cd mysql5.0.51b
#################################
note use your own version of mysql, mine is 5.0.51b
########################################
cd bin
mysql -h localhost -u root -p
////////////////////////////////
note -p that is if u use a password
////////////////////////////////////////
after this line of codes you have this
welcome note telling you the server version of mysql and your connection id
If you navigate to the bin directory of the program you just installed then type "mysql.exe"
Have a look at this guide if you get stuck with the commands
Determine the path of your MySQL installation, and add it to PATH environment variable.
SET PATH=%PATH%;C:\MySQL\bin
The above example assumes MySQL to be installed in C:\MySQL directory.
Once path is set, then you can directly execute
mysql -u root
Which logs into MySQL as root user. The -p flag can be used if password is required
It is required to execute SET PATH every time, hence you may make a batch file.