I am using Puppet v3.4.3 and Puppetlabs-mysql module v2.3.1 ( https://forge.puppetlabs.com/puppetlabs/mysql) to create database and I need to allow hosts localhost and % to use it. Both Puppet master and client run on Ubuntu-14.04 servers.
I use code like this:
mysql::db { 'mydb':
user => 'myuser',
password => 'mypass',
host => 'localhost',
grant => ['SELECT', 'UPDATE'],
}
If I try to pass both hosts as an array they get combined together:
host => ['localhost', '%'],
Mysql users:
| user | host |
+------------------+-------------------+
| username | localhost% |
If I try giving host-parameter twice I get error about duplicate declaration:
Error 400 on SERVER: Duplicate parameter 'host' for on Mysql::Db
Is what I want possible with this Puppet-module and if so how is it done?
You create one grant with your mysql::db, as in your first example. To allow the other host, you need to add a dedicated mysql::grant.
Related
I need to get an old version of a Laravel app working.
It is using Laravel version 4.2.2.
I have a docker setup:
version: '3.5'
services:
laravel:
depends_on:
- database
...
database:
image: mysql:5
hostname: database
environment:
MYSQL_ROOT_PASSWORD: mypass
MYSQL_DATABASE: mydb
MYSQL_USER: myuser
MYSQL_PASSWORD: mypass
I added database data to config (Laravel 4.2)
'connections' => array (
'mysql' => array (
'driver' => 'mysql',
'host' => 'database', // as name of db container
'database' => 'mydb', // this database exists, I can see in PhpMyAdmin
'port' => '3306',
'username' => 'root', // I can login with these credentials in PhpMyAdmin and CLI
'password' => 'mypass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
...
I can login to a phpmyadmin container with these credentials, and I also can login from the CLI of laravel container with mysql -h database -u root -p.
If I dump the connection in Laravel Illuminate/Database/Connectors/Connector.php class, I see that the correct config is being used.
public function createConnection($dsn, array $config, array $options)
{
$username = array_get($config, 'username');
$password = array_get($config, 'password');
// dd($dsn);
// dd($config);
// dd($username); dd($password);
return new PDO($dsn, $username, $password, $options);
}
Gives:
string(59) "mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=mydb"
array(11) { ["driver"]=> string(5) "mysql" ["host"]=> string(8) "database" ["port"]=> string(4) "3306" ["database"]=> string(6) "mydb" ["username"]=> string(4) "root" ["password"]=> string(21) "mypass" ["charset"]=> string(4) "utf8" ["collation"]=> string(15) "utf8_unicode_ci" ["prefix"]=> string(0) "" ["unix_socket"]=> string(27) "/var/run/mysqld/mysqld.sock" ["name"]=> string(5) "mysql" }
root` (username)
mypass (password)
Why do I still get the error?
I found the problem.
If you look at the $dsn-value in Illuminate/Database/Connectors/Connector.php createConnection:
string(59) "mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=mydb"
You see that host=database is simply missing, even though I added it in laravel config.
Adding it manually solves this problem:
$dsn= "mysql:unix_socket=/var/run/mysqld/mysqld.sock;host=database;dbname=mydb";
Even though I added the host in the config, I found out that in another database-config there was a unix_socket-value added to mysql configuration. Laravel takes either the socket or the host information. My host-value has not been overriden, but the presence of unix_socket-value in the other configuration prevented connection via host.
So I simply removed the unix_socket in another config.
The possible reasons for SQLSTATE[HY000] [2002] is as follows
MYSQL is not running
Incorrect database settings
Insufficient server resources
Based on the analysis of your scenario, the possible reasons is the incorrect database settings
Possible recommendation from my side is to find the right database settings in Laravel.
Make sure the host is correct
Make sure the username is correct
Make sure the password is correct
In most of the cases the problem lies on the host resolution in docker for that I recommend you to find the right hostname and port that the laravel container can able to connect with the mysql container
Following the steps described in this tutorial or verifying the steps with your existing system may solve your problem.
I'm trying to create a connection to mysql from ruby script using login path.
I've set the login path in the following way:
mysql_config_editor set --login-path=login-path --host=host-name --user=user --password
Now in my ruby script I have the following line:
require 'mysql2'
$mysql_connection = Mysql2::Client.new(:default_file => '~/.mylogin.cnf',:default_group => 'login-path')
And I get the following error:
error: Found option without preceding group in config file:
/home/user/.mylogin.cnf at line: 3 Fatal error in defaults handling.
Program aborted
When I'm connecting like this, it succeed:
require 'mysql2'
$mysql_connection = Mysql2::Client.new(:host => 'host-name', :username => "user", :password => "password", :database => 'database_name')
What am I doing wrong?
I think the problem is with your 'default_group' setting. I have standard mysql setup using a typical login-path of 'client', eg:
% mysql_config_editor print
[client]
password = *****
and the following connect works with no issue:
#client = Mysql2::Client.new(host: MySQL_Host, username: MySQL_User, default_group: 'client', database: MySQL_Database)
I am trying to provision a Vagrant machine using this puppet module.
The Hello world is simple, its something like this:
class { '::mysql::server':
root_password => 'strongpassword',
remove_default_accounts => true
}
But my main objective is, when you do vagrant up the first time, the vagrant machine will have a mysql server ready for external access and be able to accept external connections from the host with a specific user.
This is what I tried:
class { '::mysql::server':
root_password => 'strongpass',
remove_default_accounts => false,
override_options => {
mysqld => { bind-address => '0.0.0.0'} //allow entry connections from any ip
}
}
//create a database called `mydb`, a user and a password
mysql::db { 'mydb':
user => 'admin',
password => 'secret',
host => '192.168.33.1',
}
//assign it all the privileges to that user
mysql_grant { 'admin#192.168.33.1/*.*':
ensure => 'present',
options => ['GRANT'],
privileges => ['ALL'],
table => '*.*',
user => 'admin#192.168.33.1',
}
This is the test I do in order to see if it worked:
Destroy the vagrant machine if already exists: vagrant destroy
Create the vagrant machine: vagrant up
Try to connect with MySQLWorkbench.
Question
The weird thing is, when I try to do a connection, it is just not possible, but if I do a vagrant reload --provision then I am able to connect it with MySQLWorkbech. What am I doing wrong?
I have created a freebie site for a local school where the students can have their own blog. I can get 150Mb MySQLdatabases at no charge through my hosts, but the WPMU install keeps maxing out. This is alot down to students not clearing spam!
I want to be able to bond more than one database (on different host IPs) to serve the installation. I've looked at HyperDB but can't get it to work.
$wpdb->add_database(array(
'host' => DB_HOST, // If port is other than 3306, use host:port.
'user' => DB_USER,
'password' => DB_PASSWORD,
'name' => DB_NAME,
));
$wpdb->add_database(array(
'host' => '***.***.***.51', // my second, blank database on a diff IP.
'user' => 'USER2', // a diff username.
'password' => DB_PASSWORD, // the same password as in the master config.php.
'name' => 'newdbase_2012', // my second database name.
));
Any help would be really, really appreciated in either getting this to work, or pointing out a new way of doing it!!!
I am trying to setup my database config as demonstrated here: http://kowsercse.com/2011/09/04/kohana-tutorial-beginners/
I have cut and pasted the database.php with my mysql credentials. I then get an error which I fixed by renaming the file to Database.php. the next issue is that my credentials don't change no matter what I put in.
The error shows:
Database_Exception [ 2 ]: mysql_connect() [function.mysql-connect]: Access denied for user 'ivanh'#'localhost' (using password: NO)
MODPATH/database/classes/Kohana/Database/MySQL.php [ 67 ]
62 catch (Exception $e)
63 {
64 // No connection exists
65 $this->_connection = NULL;
66
67 throw new Database_Exception(':error',
68 array(':error' => $e->getMessage()),
69 $e->getCode());
70 }
71
72 // \xFF is a better delimiter, but the PHP driver uses underscore
So no matter what I insert, username, host and password values do not change.
My code in Database.php is then copied from: http://kohanaframework.org/3.3/guide/database/config
firstly with my own database values then after as is. With no luck.
Other info: I'm creating this on a shared unix host.
Kohana 3.1.4: Database_Exception [ 2 ]: mysql_connect(): Access denied seems like a similar issue without a resolution.
Any help would be great, thanks.
Try These Steps:
Step 1:
Go to bootstrap.php
path- kohana\application\bootstrap.php
Un-comment the below line for database access
'database' => MODPATH.'database', // Database access
Step 2:
Go to Your config folder,
create the database.php file if not created, with below codes by giving your MySql credential
Path: kohana\application\config\database.php
Notes: First create a database in your Mysql
If the problem is not solved check your MySql settings too..there may be a error
<?php defined('SYSPATH') OR die('No direct access allowed.');
return array
(
'default' =>
array
(
'type' => 'MySQL',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
* array variables system variables as "key => value" pairs
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'database' => 'CHANGE YOUR DATABASE NAME HERE',
'username' => 'CHANGE YOUR USER NAME HERE',
'password' => 'CHANGE YOUR PASSWORD HERE',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
),
'remote' => array(
'type' => 'MySQL',
'connection' => array(
/**
* The following options are available for PDO:
*
* string dsn Data Source Name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*/
'dsn' => 'mysql:host=localhost;dbname=CHANGE YOUR DATABASE NAME HERE',
'username' => 'CHANGE YOUR USER NAME HERE',
'password' => 'CHANGE YOUR PASSWORD HERE',
'persistent' => FALSE,
),
/**
* The following extra options are available for PDO:
*
* string identifier set the escaping identifier
*/
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
),
);
I am going to make the following assumptions:
You are consequently writing "Database.php" because the file in APPPATH/config containing the code you copied does indeed start with a capital letter.
You haven't changed the config reader.
Database::instance() will request a config array from the Kohana::$config if none is supplied. Config_File::load() will then loop through all found /config/database.php's found in APPPATH, enabled modules and SYSPATH.
Unix filesystems are case sensitive, notice the lowercase 'd' Kohana is looking for versus your uppercase 'D'.
If you did name it 'database.php' and not 'Database.php', click on 'Environment' and then 'Included files' on the error page and make sure it is included. If it's not, do some backtracking and try to find out when things stop behaving as they should, followed by why.
Edit: I don't know how I missed the "renamed it to Database.php" part, but that did not fix anything.