I'm installing mysql on windows using batch script.
#echo off
echo Installing MySQL Server. Please wait...
msiexec /i "D:\MySQL\mysql-installer-community-5.6.34.0.msi" /qn /norestart
echo Configurating MySQL Server...
"%Program Files%MySQL\MySQL Server 5.6\bin\mysqlinstanceconfig.exe" -i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER DatabaseType=MYISAM Port=3306 Charset=utf8
echo MySQL has been installed successfully
setx PATH "%%Program Files%\MySQL\MySQL Server 5.5\bin%;"
pause
cd /
c:
mysql --user=root --password=mysql -e "CREATE USER 'myuser'#'localhost' IDENTIFIED BY 'user1';"
;
mysql --user=root --password=mysql -e "GRANT ALL ON mydatabase.* TO 'myuser'#'%' IDENTIFIED BY 'user1' WITH GRANT OPTION;
In the above script any mistake is there.I am getting the error.
"The system cannot find the path specified"
This following script seems to work for me. I just removed the spaces between %Program Files% and added a backward slash after %ProgramFiles%.
#echo off
echo Installing MySQL Server. Please wait...
msiexec /i mysql-5.5.25a-winx64.msi /passive
echo Configurating MySQL Server...
"%ProgramFiles%\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe" -i -q
ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER DatabaseType=MYISAM
Port=3306 Charset=utf8
echo MySQL has been installed successfully
setx PATH "%ProgramFiles%\MySQL\MySQL Server 5.5\bin%;"
pause
P.S. Batch script and installer are present in the same folder.
Related
everyone. Ive started to learn bash and DevOps, lost 2 days, but I cant understand the following:
requirments
Centos 7
DB mysql
zabbix server version 4
mariadb
I need to write bash script (script at the end of the question), that creates and runs zabbix server (exactly 4 version). When I run the script manually step by step (inserting each command in pwsh by hand) in two ways for db creating (example1 or example2) - it is executed properly: zabbix db is created, all services started, zabbix frontend is working well.
But when I run the script as root user or as local user by command:
>sh -c /home/zabbix_server
script is finished by:
>Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
>Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
>Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
there are no error messages during or at the end of the script, but when I try manually execute the command create db (example1 or example2), it's doesn't matter:
#Create DB (example1)
mysql -uroot <<EOF
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'#'localhost' identified by 'zabbix';
grant all privileges on zabbix.* to 'zabbix'#'localhost';
EOF
#Create DB (example2)
mysql -u root -e "CREATE DATABASE zabbix; CREATE USER zabbix#localhost identified by 'zabbix'; GRANT ALL ON zabbix.* to zabbix#localhost WITH GRANT OPTION;"
I get the error message: ... db can't be created, zabbix base exist
But the result of the command:
>show databases;
doesn't show db zabbix in db list.
script
#!/usr/bin/env bash
setenforce 0
#Install the repository configuration package
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
yum clean all
#Install Zabbix server, frontend, agent, database
yum install zabbix-server-mysql -y
yum install zabbix-web-mysql -y
yum install zabbix-agent -y
yum install mariadb-server -y
#Start DB
systemctl start mariadb
#Create DB (example1)
mysql -uroot <<EOF
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'#'localhost' identified by 'zabbix';
grant all privileges on zabbix.* to 'zabbix'#'localhost';
EOF
#Create DB (example2)
mysql -u root -e "CREATE DATABASE zabbix; CREATE USER zabbix#localhost identified by 'zabbix'; GRANT ALL ON zabbix.* to zabbix#localhost WITH GRANT OPTION;"
#Import initial schema and data
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix
#Configure the database for Zabbix server
echo DBPassword=zabbix >> /etc/zabbix/zabbix_server.conf
#Start zabbix server
systemctl start zabbix-server
#Configure frontend
sed -i 's:# php_value date.timezone.*:php_value date.timezone Europe\/Minsk:g' /etc/httpd/conf.d/zabbix.conf;
#Start httpd
systemctl restart zabbix-server zabbix-agent httpd
#Make Zabbix server and agent processes start at system boot
systemctl enable zabbix-server zabbix-agent httpd
Depending on what you want to achieve, this may be a good suggestion:
CREATE DATABASE IF NOT EXISTS zabbix;
This makes the call idempotent!
The problem was, that the script contains a \r (CR) at the end (0d). Remove it with:
tr -d '\r' < old_name_script > new_name_script
And the script works fine.
If it will be useful, there is fully working example of the script, that creates zabbix server:
#!/usr/bin/env bash
#Disable SELinux
enforceStatus=getenforse
if [ "$enforceStatus" != "Permissive" ]; then
setenforce 0
fi
#Install the repository configuration package
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum clean all
#Install Zabbix server, frontend, agent, database, httpd
yum install zabbix-server-mysql -y
yum install zabbix-web-mysql -y
yum install zabbix-agent -y
yum install mariadb mariadb-server -y
yum install httpd -y
#Start and add to autostart DB mariadb
systemctl start mariadb
systemctl enable mariadb.service
#Create DB (example1)
mysql -uroot <<EOF
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'#'localhost' identified by 'zabbix';
grant all privileges on zabbix.* to 'zabbix'#'localhost';
EOF
#Import initial schema and data
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql zabbix
#Configure the database for Zabbix server
echo DBPassword=zabbix >> /etc/zabbix/zabbix_server.conf
#Configure frontend
sed -i 's:# php_value date.timezone.*:php_value date.timezone Europe\/Minsk:g' /etc/httpd/conf.d/zabbix.conf;
#Start zabbix server processes start at system boot
systemctl restart zabbix-server
systemctl enable zabbix-server
#Start httpd processes start at system boot
systemctl restart httpd
systemctl enable httpd
#Start zabbix-agent processes start at system boot
systemctl restart zabbix-agent
systemctl enable zabbix-agent
#Add permissions to irewall
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
I am setting up a new vagrant box for a NodeJS project. For the database I will be using MySQL. I have setup a provisioning script to install everything I need and it all works great apart from accessing MySQL from the host machine (Using Sequel Pro). I have it working but I have to edit the /etc/mysql/my.cnf file in order to comment out the bind-address line.
Is there anyway to do this on the command line so I can add it to the provisioning script? If this is possible then any other dev that I share the project with would only need to do vagrant up and have everything ready to go.
Below are the parts of my script relevant to the MySQL setup:
#!/bin/bash
# Variables
DBHOST=localhost
DBNAME=vagrant
DBUSER=vagrant
DBPASSWD=test123
# Update packages
apt-get update
# Install MySQL
debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASSWD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWD"
apt-get install -y mysql-server
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
mysql -uroot -p$DBPASSWD -e "CREATE USER '$DBUSER'#'localhost' IDENTIFIED BY '$DBPASSWD'"
mysql -uroot -p$DBPASSWD -e "GRANT ALL PRIVILEGES ON $DBNAME.* TO '$DBUSER'#'localhost'"
mysql -uroot -p$DBPASSWD -e "CREATE USER '$DBUSER'#'10.0.2.2' IDENTIFIED BY '$DBPASSWD'"
mysql -uroot -p$DBPASSWD -e "GRANT ALL PRIVILEGES ON $DBNAME.* TO '$DBUSER'#'10.0.2.2'"
echo "Installed MySQL"
Thanks for any help you can provide.
You should be able to achieve this using sed command from your script
apt-get install -y mysql-server
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
...
Note you might need to restart the service to take effect if you provision and do not restart the instance for the 1st use, add this then to your script
service mysql stop
service mysql start
sql docker:
FROM ubuntu:latest
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install mysql-client mysql-server curl
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
ADD database.sql /var/db/database.sql
ENV user admin
ENV password admin
ENV url file:/var/db/database.sql
ENV right WRITE
ADD ./start-database.sh /usr/local/bin/start-database.sh
RUN chmod +x /usr/local/bin/start-database.sh
EXPOSE 3306
CMD ["/usr/local/bin/start-database.sh"]
--------\------
startdatabase.sh
#!/bin/bash
# This script starts the database server.
echo "Creating user $user for databases loaded from $url"
# Import database if provided via 'docker run --env url="http:/ex.org/db.sql"'
echo "Adding data into MySQL"
/usr/sbin/mysqld &
sleep 5
curl $url -o import.sql
# Fixing some phpmysqladmin export problems
sed -ri.bak 's/-- Database: (.*?)/CREATE DATABASE \1;\nUSE \1;/g' import.sql
# Fixing some mysqldump export problems (when run without --databases switch)
# This is not tested so far
# if grep -q "CREATE DATABASE" import.sql; then :; else sed -ri.bak 's/-- MySQL dump/CREATE DATABASE `database_1`;\nUSE `database_1`;\n-- MySQL dump/g' import.sql; fi
mysql --default-character-set=utf8 < import.sql
rm import.sql
mysqladmin shutdown
echo "finished"
# Now the provided user credentials are added
/usr/sbin/mysqld &
sleep 5
echo "Creating user"
echo "CREATE USER '$user' IDENTIFIED BY '$password'" | mysql --default-character-set=utf8
echo "REVOKE ALL PRIVILEGES ON *.* FROM '$user'#'%'; FLUSH PRIVILEGES" | mysql --default-character-set=utf8
echo "GRANT SELECT ON *.* TO '$user'#'%'; FLUSH PRIVILEGES" | mysql --default-character-set=utf8
#if [ "$right" = "WRITE" ]; then
#echo "adding write access"
echo "GRANT ALL PRIVILEGES ON *.* TO '$user'#'%' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql --default-character-set=utf8
echo "finished"
#fi
# And we restart the server to go operational
mysqladmin shutdown
echo "Starting MySQL Server"
/usr/sbin/mysqld
When I run this docker file of sql it runs.
But when I link it to application using the command
$ docker run --link mysqldb -d abc // here abc is image name of application
& mysqldb is name of sql db image.
it terminates the server and shows cannot open the connection.
Even though I had provided privileges to it and also provided the ip addr of sql image to application image.
I have seen that my sql server is running properly and it connect to mysql client also.
Please proivide a better solution**
I am using below code to install mysql silently on windows using a batch file..
Seems like it is ignoring /qn
also i have tried with /quiet but that is also not working.
it is just reading line and moving cursor to next line.
echo off
cls
echo Starting MySQL mysql-essential-5.0.88-win32 install
msiexec /i "mysql-essential-5.0.88-win32.msi" /qn INSTALLDIR="C:\Program Files\MySQL" /L* "C:\Program Files\MySQL\mysql-log.txt"
echo MySQL mysql-essential-5.0.88-win32 installed successfully
echo Creating MySQL Windows service
"C:\Program Files\MySQL\bin\mysqlinstanceconfig.exe" -i -q ServiceName="MySQL service" RootPassword="newRootPassword" ServerType=SERVER DatabaseType=MYISAM Port=3306
RootCurrentPassword=mysql
echo MySQL Instance Configured. Service started.
pause
I have tried directly running command but it is completely ignoring
NOTE: Setup is working fine if i run it directly, issue is with silent installation only
please suggest.
thanks.
/ni
/q
/qn
/quiet
/s
/silent
Try dashes instead of forward slashes too (-S instead of /S), and check both upper case and lower case.
Hope that helps.
#Echo off
FOR /F "tokens=5" %%a in ('netstat -aon ^| find "3306" ^| find "LISTENING"') do taskkill /f /pid %%a
cls
TIMEOUT 1
if "%ProgramFiles(x86)%" == "" (
set "MySQLServerPath=%ProgramFiles%\MySQL\MySQL Server 5.0\bin"
) else (
set "MySQLServerPath=%ProgramFiles(x86)%\MySQL\MySQL Server 5.0\bin"
)
REM echo Configurating MySQL Server ...
"%MySQLServerPath%\MySQLInstanceConfig.exe" -i -q ServerType=DEVELOPER ConnectionUsage=DSS Port=3306 StrictMode=yes Charset=utf8 DatabaseType=MIXED ServiceName=root RootPassword=root
REM echo MySQL has been configured successfully.
I am working on java desktop application in which i use MYSQL database, but i have a problem , i want to embed MYSQL database, for this i want a script to install the MYSQL, i need Help to install MYSQL from batch file (windows).
i am using this script
#echo off
echo Installing MySQL Server. Please wait...
msiexec /i "mysql-installer-community-5.6.14.0.msi" /qn
echo Configurating MySQL Server...
"%ProgramFiles%\MySQL\MySQL Server 5.6\bin\mysqlinstanceconfig.exe"
-i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER
DatabaseType=MYISAM Port=3306 Charset=utf8
echo Installation was successfully
i get the error,"The system cannot find the path specified".
Any help will be appreciated.
I suspect that %ProgramFiles% is pointing to the wrong folder.
Try #echo %ProgramFiles% from a file to see what folder it is looking in. You have to make sure that it is not in the Program Files x86 folder.
I found this link also, maybe it can help you out?
Source: how to get program files x86 env variable?
EDIT
To be just sure, can you try it with the full path instead of the system variable?
Like this,
#echo off
echo Installing MySQL Server. Please wait...
msiexec /i "mysql-installer-community-5.6.14.0.msi" /qn
echo Configurating MySQL Server...
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqlinstanceconfig.exe"
-i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER
DatabaseType=MYISAM Port=3306 Charset=utf8
echo Installation was successfully
or even
#echo off
echo Installing MySQL Server. Please wait...
msiexec /i "mysql-installer-community-5.6.14.0.msi" /qn
echo Configurating MySQL Server...
cd "C:\Program Files\MySQL\MySQL Server 5.6\bin\" <-- set folder first, then run executeable
mysqlinstanceconfig.exe
-i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER
DatabaseType=MYISAM Port=3306 Charset=utf8
echo Installation was successfully
My batch file complete:
#echo off
cls
echo ==========================================
echo MySQL Server - Installation - v.17/03/2014
echo ==========================================
echo .
echo .
rem ------------------------------------------------
echo Installing. Wait ...
msiexec /i "mysql-5.5.28-win32.msi" /qn
echo Done.
rem ------------------------------------------------
echo .
echo .
rem ------------------------------------------------
echo Configurating. Waiting ...
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin\"
mysqlinstanceconfig.exe -i -q ServiceName=MySQL RootPassword=mypassword ServerType=DEVELOPER DatabaseType=INODB Port=myport Charset=utf8
echo Done.
rem ------------------------------------------------
echo .
echo .
rem ------------------------------------------------
echo Creating access to user. Waiting ...
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin\"
mysql -uroot -pmypassword --execute="GRANT ALL PRIVILEGES ON . TO 'root'#'%%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;"
mysql -uroot -pmypassword --execute="FLUSH PRIVILEGES;"
echo Done.
rem ------------------------------------------------
echo .
echo .
echo Installation ready.
echo .
echo .
pause