Configure MySQL in SublimeText 3 - mysql

I want to configure MySQL in SublimeText 3, I found that the configuration is from Build System / New Build System ...
My written code is as follows:
{
"cmd": ["C: /xampp/mysql/bin/mysql.exe", "-u", "dorbezo", "-P", "Dorbezo123", "-h", "192.168.1.99", " -e "," source $ file "," -t "],
"selector": "source.sql",
"quiet": true}
My credentials to access MySQL from Workbench are the following:
user: dorbezo,
pass: Dorbezo123,
host: port: 192.168.1.99:3306
Am I entering the connection correctly? It is worth mentioning that I connect via VPN and I have ** xampp ** started when I try to run a query, getting the following error:
** show databases; **
Unknown suffix 'D' used for variable 'port' (value 'Dorbezo123')
C: /xampp/mysql/bin/mysql.exe: Error while setting value 'Dorbezo123' to 'port'
I also mention that the port where ** xampp ** connects is 3307, since 3306 (which I use in Workbench) causes me conflict.

There are several problems with your .sublime-build file.
Your command path "C: /xampp/mysql/bin/mysql.exe" has a space in it but perhaps that was pasted into your post incorrectly. I would have expected something more like this on Windows: "C:\\xampp\\mysql\\bin\\mysql.exe".
You are using an uppercase -P for your password, it should be a lowercase -p.
You possibly need to add the port number with the uppercase "-P", "3306". I say 'possibly' because 3306 is the default port for MySQL so you may not need to specify it at all.
Using long form options is generally a good idea because they prevent letter case mistakes. e.g. --user, --password, --host, --port, --execute, --table.
Here is a MySQL.sublime-build file for you to try, the long options (with my details) work for me on Linux:
{
"cmd": ["C:\\xampp\\mysql\\bin\\mysql.exe", "--user=dorbezo", "--password=Dorbezo123", "--host=192.168.1.99", "--port=3306", "--execute=source $file", "--table"],
"selector": "source.sql"
}
Clearly storing a password in a .sublime-build file is a security risk. You should consider creating a MySQL user with an insecure password which has limited privileges.
There is also the SQLTools Sublime Text plugin which you could install, see here for the documentation. Instead of your connection details being stored in a .sublime-build file you would add them in a SQLToolsConnections.sublime-settings settings file. The documentation link above has detailed examples. I suspect you might find using this plugin easier than managing the build file. Using this plugin means there is less of a password security issue; if you use null in the password field (not in quotes) then the plugin will prompt for the password and then remember it for the session (I think).

Related

ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server

So I am stuck with this error when trying to connect my node.js application with MySQL.
It won't let me connect to MySQL from localhost, not a single command is working.
The MySql workbench also says the same
I can't use any database commands since it's not letting me access mysql. Gone through almost all possible solutions on the internet none of them worked. Please help me out here even an explanation for this would help if not the solution.
In order to access you must do the following steps :
1. Run the terminate with user permission.
2. Access the path where you have mysql installed.
3. Put the following sentence.
mysql.exe -u root -ppasw
-u : It is the user.
-p : the password but next to the p without space.
If it does not work try this in windows cmd
To restore to a single concrete database.
mysqlbinlog -database='yourFile.00004'
Explanation : The Binary log.
It has replaced the old update file.
Its mission is to update the DBs during a recovery operation.
Replication masters are used as a reminder of the statements to be sent to the slave servers.
If the name is not specified, the host is chosen.
Performance drop of 1%.
Active bins must not be opened during execution.
If you put extension to the file, it is ignored.
A new BIN_LOG file is created when :
The server is restarted
A Flush binary Logs is made
The size specified in MAX_BINLOG_SIZE is exceeded.
The files that are generated have an extension that are sequential numbers and represent the order (index) of their creation controlled by the name host_name.index.
To activate and decomment the log-bin my.ini directive. If log-bin=file is used, that name will be used to name the sequence of files.
To delete index files.
purge binary before date-time (in this format "yyyy-mm-dd hh:mm:ss" or now() or interval....)
purge binary logs to filename; deletes up to this file (this one not included)
reset master -> deletes all files
To disable the binary log, the session variable is used.
SQL_LOG_BIN : Up to version 5.6 this one is
EXECUTE DB : binlog-do-db=BD
DOES NOT RUN DB : binlog-ignore-db=BD
The commands are the continuation of the binary log.
create database
alter database
drop database
To see the content of a binary file (must not be open).
mysqlbinlog "file with its path".
To restore several binary files must be done in one step.
mysqlbinlog file1 file2 file3 file3 | mysql -u root -ppassword
To restore.
Overwrite the file >
Adds in the content respecting the content >>
To restore to a single concrete database.
mysqlbinlog -database='filenamebinlog.00004'
If the above does not work, do this first
Another option
ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server
Cause :
mysql only has one root user, select MD5 after changing root password, then submit, reboot.
Login appears "The host 'localhost' is not allowed to connect to this MySQL server..."
Try the user table in another mysql library, overwrite, no, it is estimated that the version is different
Resolve :
Edit my.ini
Add a sentence to [mysqld]: skip-grant-tables
For example :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
The purpose is :
Bypass MySQL access control, anyone can log in to the MySQL database as an administrator in the console.
It should be noted that after changing the password, the MySQL server must be stopped and restarted to take effect.
Restart the mysql service!

How do I automate mysqladmin, and mysql_secure_installation queries with .mylogin.cnf?

I am looking at automating a couple things when installing MySQL to a new host using a Chef server. These include:
mysqladmin -u root password {password_here}
mysql_secure_installation
I've created a .mylogin.cnf file with two login-paths, admin (which is root user), and mysqluser (non root user).
My issues are that I can't get (or understand how) .mylogin.cnf to create the DB users and password; and I can't automate the mysql_secure_installation using --defaults-file=.mylogin.cnf (assuming that's how the --defaults-file works) even though it's not specifying a login-path. Initially I was running the mysql queries via command line to harden the service, but was told that mysql_secure_installation uses --no-defaults, and --defaults-file to automate this particular task, but haven't found much online about those arguments.
Can anyone point me in the right direction?
The option --defaults-file is NOT used for setting/changing options in whichever tool you are running. This file is only used for specifying connection options (ie: host, username, socket, etc). For mysql_secure_installation specifically, you might try --use-default which, according to the manual, is used for unattended execution. In MySQL 5.7, a random root password is generated and printed in the error log. Simply grep this file for that password in your Chef script, then connect to MySQL and run whatever commands you need to create new users, dbs, etc. FYI, the generated root password is expired so when you connect, you have to change it first before you can do anything else.

bootstrap error trying to enable drupal module with drush

Trying to install my first drupal module. Following the book did not work because of an "FTP" error so I installed drush. Download seemed to work now the enable command gives me this error. I'm a noob with ubuntu and every part of drupal. Help. Thanks.
NNH#comp:/var/www/drupal$ sudo drush en module_filter
Command pm-enable needs a higher bootstrap level to run - you will [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'en module_filter' could not be executed. [error]
Drush was not able to start (bootstrap) the Drupal database. [error]
Hint: This error often occurs when Drush is trying to bootstrap a
site that has not been installed or does not have a configured
database.and tried it.
Drush was attempting to connect to :
Drupal version : 7.14
Site URI : http: //default
Database driver : mysql
Database hostname : localhost
Database username : drupal7
Database name : drupal7
Default theme : garland
Administration theme: garland
PHP configuration :
Drush version : 5.3
Drush configuration:
Drupal root : /var/www/drupal
Site path : sites/default
Modules path : sites/all/modules
Themes path : sites/all/themes
File directory path: sites/default/files
%paths : Array
You can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command
line or $options['uri'] in your drushrc.php file.
Possibly related:
NNH#comp:~$ sudo dpkg-reconfigure -plow phpmyadmin
[sudo] password for NNH:
/usr/sbin/dpkg-reconfigure: phpmyadmin is broken or not fully installed
Drush is basically a command-line interface to interact, manage and configure Drupal and its modules. So if you like to use Drush for any operations pertaining database, you have to go through loop address ie., localhost. But it seems like Drush understands 127.0.0.1 as loop address but not localhost.
Simply by defining these in settings.php you are allowing the Drush to proceed with any database related operations.
Instead of just this
'host' => 'localhost',
use this,
'host' => php_sapi_name() == 'cli' ? '127.0.0.1' : 'localhost',
You typically recieve the error
Command pm-enable needs a higher bootstrap level to run - you will
[error] need invoke drush from a more functional Drupal environment to
run this command.
when you aren't in the root of the site when running the command.
If the error persist try connecting to MySQL straight from the prompt. Try connecting using the values from the Drush output, ie:
mysql -hlocalhost -udrupal7 -p drupal7
If it is working and the site is working then you most likely can rule out database connection problem. Assuming you are developing locally on your own box, you can try changing localhost to 127.0.0.1 in settings.php. This seem to have helped some people.
The site URI setting seems a bit odd.

Weird mySQL behavior in Ubuntu 10.10

I'm having some serious trouble with a freshly installed copy of mySQL server under Ubuntu 10.10. I installed with apt and supplied a password at that time. Installation went fine, but the server is behaving very strangely.
First, to test the database, I created a php file with
mysql_connect("localhost", "root", "myPassword") or die(mysql_error());
where myPassword is the one I entered when it asked, during installation. That gave me an access denied error. I tried to shell into the mySQL server to pursue a solution I read about. The normal syntax didn't work, and to get anything but "access denied", I had to do
mysql -u root password myPassword
However, instead of a mysql shell, it just spits out a list of parameters and variables. So at this point, I'm stumped; I haven't worked with mySQL through a command line in a couple of years, but none of this behavior is familiar, and I can't find a way to interact with the server.
Any help would be appreciated.
The mysql command-line parameter for supplying a password is -p, not password. You should also leave out spaces. For example:
mysql -uroot -pmyPassword
If you don't want to risk your password being exposed...
mysql -uroot -p
...will prompt you for your password and hide the characters as you type them.
If you have apparmor installed (this is default) it can cause problems when you go outside the narrowly-defined defaults set up by ubuntu.
The things that mysql is allowed to touch is defined here: /etc/apparmor.d/abstractions/mysql
If you've put your socket file elsewhere, you would get an access-denied message.
To look at things more closely, run your mysql client like so:
strace -e file mysql <blah blah>
This will print out any system-level file operations on stderr. You can then see exactly which operation is causing the permissions error. If you don't see an issue, you might use -e network instead, to see network operations.

Is there a simple tool to convert mysql to postgresql syntax?

I've tried the tools listed here, some with more success than others, but none gave me valid postgres syntax I could use (tinyint errors etc.)
There's a mysqldump option which makes it output PostgreSQL code:
mysqldump --compatible=postgresql ...
But that doesn't work too well.
Instead, please see the mysql-to-postgres tool as described in Linus Oleander's answer.
Try this one , it works like charm !!
http://www.sqlines.com/online
After some time on Google I found this post.
Install the mysql2psql gem using [sudo] gem install mysql2psql.
Create a config file by running mysql2psql. You'll see an error but a mysql2psql.yml file should have been created.
Edit mysql2psql.yml
Run mysql2psql again to migrate you data.
Tip: Set force_truncate to true in your mysql2psql.yml config file if you want the postgresql database to be cleared before migrating your data.
Install pgloader on Debian or Ubuntu:
sudo apt install pgloader
Login as the postgres user and create a database
sudo su postgres
createdb -O user db_migrated
Transfer data from the mysql database to postgresql
pgloader mysql://user#localhost/db postgresql:///db_migrated
Check also Dimitri Fontaine's rewrite of pgloader from python to common lisp so that he could implement real threading.
Installation on other platforms
To install pgloader on Windows, you can use the Windows Subsystem for Linux.
To install pgloader on Mac, you can use: brew install --HEAD pgloader.
I've used py-mysql2pgsql. After installation it needs only simple configuration file in yml format (source, destination), e.g.:
# if a socket is specified we will use that
# if tcp is chosen you can use compression
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: mysql2psql
password:
database: mysql2psql_test
compress: false
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: mysql2psql
password:
database: mysql2psql_test
Usage:
> py-mysql2pgsql -h
usage: py-mysql2pgsql [-h] [-v] [-f FILE]
Tool for migrating/converting data from mysql to postgresql.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Show progress of data migration.
-f FILE, --file FILE Location of configuration file (default:
mysql2pgsql.yml). If none exists at that path,
one will be created for you.
More on its home page https://github.com/philipsoutham/py-mysql2pgsql.
Have a look at PG Foundry, extra utilities for Postgres tend to live there. I believe that the tool you're looking for does exist though.
There is one piece of pay software listed on this postgresql page:
http://www.postgresql.org/download/products/1
and this is on pgFoundry:
http://pgfoundry.org/projects/mysql2pgsql/
This page lists the syntax differences, but a simple working query converter i haven't found yet. Using an ORM package instead of raw SQL could prevent these issues.
I'm currently hacking up a converter for a legacy codebase:
function mysql2pgsql($mysql){
return preg_replace("/limit (\d+), *(\d+)/i", "limit $1 offset $2", preg_replace("/as '([^']+)'/i", 'as "$1"', $mysql)); // Note: limit needs order
}
For CREATE statements, SQLines converts most of them online. I still had to edit the mysqldump afterwards, though:
"mediumtext" -> "text", "^LOCK.*" -> "", "^UNLOCK.*" -> "", "`" -> '"', "'" -> "''" in 'data', "0000-00-00" -> "2000-01-01", deduplicate constraint names, " CHARACTER SET utf8 " -> " ".
"int(10)" -> "int" was missed in the last table, so pass that part of the mysqldump through http://www.sqlines.com/online again.
you will most likely never get a tool for such task which would do all of your job for you. be prepared to do some refactoring work yourself.