Michaelbarbosa Posted October 30, 2015 Report Posted October 30, 2015 How can I write a automated script to create a database. I need a bat file or cmd file to be created if executed that cmd file I have database created
Spartan Posted October 30, 2015 Report Posted October 30, 2015 SQl command ni file lo petti adi batch lo pettu.. mysql -uroot -ppassword < createDb.sql;
Spartan Posted October 30, 2015 Report Posted October 30, 2015 your .sql command shud look something like this.. # uninstall if anything's already there GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'; DROP USER 'username'@'%'; DROP DATABASE IF EXISTS `tablename`; # create the user CREATE USER 'username'@'%' IDENTIFIED BY 'password'; CREATE DATABASE IF NOT EXISTS `tablename`; GRANT ALL PRIVILEGES ON `tablename` . * TO 'username'@'%';
Michaelbarbosa Posted October 30, 2015 Author Report Posted October 30, 2015 I have the script bro I just want to integrate in a bat or cmd file so that database gets created with a click just have to provide database name as a parameter
Michaelbarbosa Posted October 30, 2015 Author Report Posted October 30, 2015 How abt for MS SQL server
Spartan Posted October 30, 2015 Report Posted October 30, 2015 I have the script bro I just want to integrate in a bat or cmd file so that database gets created with a click just have to provide database name as a parameter a file unte.. kinda code copy paste chesi..save it as .bat file... mysql -uroot -ppassword < createDb.sql;
Spartan Posted October 30, 2015 Report Posted October 30, 2015 How abt for MS SQL server daniki Powershell is better.. #Import SQL Server Module called SQLPS Import-Module SQLPS -DisableNameChecking #Your SQL Server Instance Name $Inst = "YourInstanceName" $Srvr = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $Inst #database PSDB with default settings #by assuming that this database does not yet exist in current instance $DBName = "AFDB" $db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($Srvr, $DBName) $db.Create() #Confirm, list databases in your current instance $Srvr.Databases | Select Name, Status, Owner, CreateDate
Michaelbarbosa Posted October 30, 2015 Author Report Posted October 30, 2015 That's working but bro to tweak what should I do Say if my server has not setup model database as desired and I want these data files and log files to be created on a destination
Recommended Posts