wso2mi 7.1, mysql user_storage, first user - mysql

I setup the mysql database user_storage, and disabled the internal api, as per stated by documentation, but... then I'm lock out because no user was created...
How do I create the first admin user at the database?

Please make sure you have the following configuration in your deployment.toml. Also make sure you have created the user database correctly. https://ei.docs.wso2.com/en/latest/micro-integrator/setup/databases/setting-up-MySQL/#creating-the-databases
[user_store]
type = "database"
read_only = "false"
[[datasource]]
id = "WSO2_USER_DB"
url= "jdbc:mysql://localhost:3306/userdb"
username="root"
password="root"
driver="com.mysql.jdbc.Driver"
[realm_manager]
data_source = "WSO2_USER_DB"
[internal_apis.file_user_store]
enable = false

Related

Kafka connect jdbc sink upsert mode issue

I'm trying to connect replicate a table at realtime using Kafka connect. The database used is MySQLv5.7.
On working with insert and update mode separately, the columns are behaving as expected. However, when I use the upsert mode, no change is observed in the database.
Configuration File filled via UI
Sink
topic = custom-p2p
Connector Class = JdbcSinkConnector
name = sink
tasks-max = 1
Key-converter-class=org.apache.kafka.connect.storage.StringConverter
Value-converter-class=org.apache.kafka.connect.json.JsonConverter
jdbc_url=jdbc:mysql://127.0.0.1:3306/p2p_service_db4?user=root&password=root&useSSL=false
insert mode = upsert
auto create = true
auto evolve = true
Source
Connector Class = JdbcSourceConnector
name = source-new
task max = 1
key converter class = org.apache.kafka.connect.storage.StringConverter
value converter class = org.apache.kafka.connect.json.JsonConverter
jdbc url = jdbc:mysql://127.0.0.1:3306/p2p_service_db3?user=root&password=root&useSSL=false
table loading mode = timestamp+incrementing
incrementing column name = auto_id
timestamp column name = last_updated_at
topic prefix = custom-
ver
The issue that I'm having is that when the sink insert mode is changed to insert, the insertion takes place properly when changed to update, this also happens perfectly as expected, however when the value is changed to upsert, neither insertion nor update takes place.
Please let me know if something done is wrong? Why this mode is not working? Is there some alternative to this if this inserts and updates both need to be replicated in the backup DB.
Thank you in advance. Let me know if some other information is needed

Pass custom variables in MySQL connection

I am setting up a MySQL connection (in my case PDO but it shouldn't matter) in a REST API.
The REST API uses an internal authentication (username / password). There are multiple user groups accessing the REST API, e.g. customers, IT, backend, customer service. They all use the same MySQL connection in the end because they also use the same end points most of the time.
In the MySQL database I would like to save the user who is responsible for a change in a data set.
I would like to implement this on the MySQL layer through a trigger. So, I have to pass the user information from the REST API to this trigger somehow. There are some MySQL calls like CURRENT_USER() or status that allow to query for meta-information. My idea was to somehow pass additional information in the connection string to MySQL, so that I don't have to use different database users but I am still able to retrieve this information from within the trigger.
I have done some research and don't think it is possible, but since it would facilitate my task a lot, I still wanted to ask on SO if someone did know a solution for my problem.
I would set a session variable on connect.
Thanks to the comment from #Álvaro González for reminding me about running a command on PDO init.
The suggestion of adding data to a temp table isn't necessary. It's just as good to set one or more session variables, assuming you just need a few scalars.
$pdo = new PDO($dsn, $user, $password, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET #myvar = 'myvalue', #myothervar = 'othervalue'"
]);
It's also possible to set session variables at any time after connect, with a call to $pdo->exec().
$pdo->exec("SET #thirdvar = 1234");
You can read session variables in your SQL queries:
$stmt = $pdo->query("SELECT #myvar, #myothervar");
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
print_r($row);
}
You can also read session variables in triggers:
CREATE TRIGGER mytrig BEFORE INSERT ON mytable
FOR EACH ROW
SET NEW.somecolumn = #myvar;

How to fix mysql uppercase query in php and mysql

I am currently working on the website that uses ADODB library. In entire website all the queries are written in UPPERCASE.
The problem is when I run the query it doesn't work because of table name which is UPPERCASE. But when I change the table name to lowercase it works.
$sql = "SELECT * FROM MEMBERS where USERNAME = '$username'";
$db = ADONewConnection('mysql');
$db->debug = true;
$db->Connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME);
$resultFriends = $db->Execute($sql);
while ($row = $resultFriends->FetchRow()) {
var_dump($row);
die;
}
Here is the error I get:
ADOConnection._Execute(SELECT * FROM MEMBERS where USERNAME = 'fury', false) % line 1012, file: adodb.inc.php
ADOConnection.Execute(SELECT * FROM MEMBERS where USERNAME = 'fury') % line 15, file: index.php
Bear in mind I don't want to change the scripts. There are 1000 files and 10000 places.
Is there any library or are there any way that I can run this queries without error?
The version for live sire was linux kernel. but the new dev site is ubuntu.
I have done this on ubuntu/ mysql CML and it didn't work.
The solution is I had to reconfigure the mySql database in AWS/rdbs
You have to modify the “lower_case_table_names” parameter for your DB Instance(s). Prior to today, the lower_case_table_names parameter was not modifiable, with a system default of zero (0) or “table names stored as specified and comparisons are case sensitive.” Beginning immediately, values of zero and one (table names are stored in lowercase and comparisons are not case sensitive) are allowed. See the MySQL documentation for more information on the lower_case_table_names parameter.
The lower_case_table_names parameter can be specified via the rds-modify-db-parameter-group API. Simply include the parameter name and specify the desired value, such as in the following example:
rds-modify-db-parameter-group example --parameters "name=lower_case_table_names, value=1, method=pending-reboot" --region us-east-1
Support for modifying parameters via the AWS Management Console is expected to be added later this year.
setting the lower_case_table_names parameter via a custom DB Parameter Group and doing so before creating an associated DB Instance. Changing the parameter for existing DB Instances could cause inconsistencies with point-in-time recovery backups and with Read Replicas.
Amazon RDS

MySQL resource in Zend Framework

I'm starting a new project built on Zend Framework. I know all about controllers, layouts and views. But I don't know how to add a MySQL resource.
Basically, I would like to have some model classes with getters and setters and for each, a resource class witch would handle MySQL queries. These resources classes need access to a DB class which performs the actual queries. The configuration for the DB would have to be in a separate file somewhere as either XML data, .ini or PHP array.
How can I obtain that? Where should I put each the files (right now, I have the default Zend directory structure)?
You dont need to create an instace of connection to database ,Zend does it automatically..just add these following to your config file
resources.db.adapter = "PDO_MYSQL"
resources.db.isDefaultTableAdapter = true;
resources.db.params.host = "yourserver"
resources.db.params.username = "username"
resources.db.params.password = "pwd"
resources.db.params.dbname = "dbname"
you can use it later
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
Zend comes with a set of DB classes that you can use. Documentation is here: http://framework.zend.com/manual/en/zend.db.html Before asking questions like this please do a bit of Googling.
[general]
db.adapter = PDO_MYSQL
db.params.host = server
db.params.username = username
db.params.password = password
db.params.dbname = dbname
$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$DB = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($DB);
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();

CodeIgniter: how to configure to connect to a different DB?

Currently, I have my database configuration something like this:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "my_username";
$db['default']['password'] = "my_password";
I actually want to connect to a different MySQL database hosted on a different server. Where would I find the hostname I need to use? Is there anything else I need to do besides changing the hostname?
Make an array of arrays, and always explicitly index them as needed:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "foo";
$db['default']['password'] = bar";
$db['default']['database'] = "blablabla";
$db['development']['hostname'] = "localhost";
$db['development']['username'] = "boo";
$db['development']['password'] = "par";
$db['development']['database'] = "blablabladev";
$this->dbdev = $this->load->database('development', TRUE);
Usually, you'll be able to get this information from the same place you created the database. So if you used a control panel on your web host to create the database, it's likely you will be able to find the address by looking around the control panel's MySql section.
Some web hosts don't allow remote access to the database either, so be wary of that.
To answer your second question, yes, you will likely have to change the username and password, the new values should also be found in the area where you created the database.
Apologies if this is a very generic answer.
$db['default']['hostname'] = "new.host.name.com";
Also make sure that mysql on your new.host.name.com will accept external connection, by providing your localhost IP