fabiochiu/medium-articles huggingface dataset:
Implementation of User permission with PHP & Mysql Bitwise operators.
By: Suresh Kamrushi
Tags: MySQL, Bitwise Operator, PHP

Another way to implement user permission in your application and also a good use of bitwise operator. This can be done with PHP as well as Mysql. Here I am showing how we can implement it with Mysql. Below is a sample tables with some sample data: Table 1 : Permission table to store permission name along with it bit like 1,2,4,8..etc (multiple of 2)

CREATE TABLE IF NOT EXISTS `permission` ( `bit` int(11) NOT NULL, `name` varchar(50) NOT NULL, PRIMARY KEY (`bit`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Insert some sample data into the table.

INSERT INTO `permission` (`bit`, `name`) VALUES (1, 'User-Add'), (2, 'User-Edit'), (4, 'User-Delete'), (8, 'User-View'), (16, 'Blog-Add'), (32, 'Blog-Edit'), (64, 'Blog-Delete'), (128, 'Blog-View');

Table 2: User table to store user id,name and role. Role will be calculated as sum of permissions.

Example : If user ‘Ketan’ having permission of ‘User-Add’ (bit=1) and ‘Blog-Delete’ (bit-64) so role will be 65 (1+64). If user ‘Mehata’ having permission of ‘Blog-View’ (bit=128) and ‘User-Delete’ (bit-4) so role will be 132 (128+4).

CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `role` int(11) NOT NULL, `created_date` datetime NOT NULL PRIMARY KEY (`id`) ) ENGINE=InnoDB Â DEFAULT CHARSET=latin1; INSERT INTO `user` (`id`, `name`, `role`, `created_date`) VALUES (NULL, 'Ketan', '65', '2013-01-09 00:00:00'), (NULL, 'Mehata', '132', '2013-01-09 00:00:00');

Loading permission of user : After login if we want to load user permission than we can query below to get the permissions:

SELECT permission.bit,permission.name FROM user LEFT JOIN permission ON user.role & permission.bit WHERE user.id = 1

Here user.role “&” permission.bit is a Bitwise operator which will give output as -

User-Add - 1 Blog-Delete - 64

If we want to check weather a particular user have user-edit permission or not-

SELECT * FROM `user` WHERE role & (select bit from permission where name='user-edit')

Output = No rows.

Hope this will help someone!!!!

Cheerss..!!
Eliminating MySQL replication lag for schema changes
By: Adithya K S
Tags: MySQL, Alter Table, Replication Lag

At Chargebee, our primary database technology is MySQL, hosted on Amazon RDS instances. Each of our microservices have schemas isolated from each other. All the data is further sharded horizontally with each shard storing data for a set of merchant businesses. A “shard” consists of a Multi-AZ source and one or more replicas.

As evident in the diagram above, we use MySQL Replication to scale out our database reads, adding replicas as needed to serve requests. Currently, more than 70% of the read traffic is served by the replicas. Further, updating indexes during writes involves additional overhead, so the number of indexes on the source are kept at a minimum. Although all indexes present in the source are also present in the replicas, some indexes are exclusively for the replicas and not for the source. These are typically indexes for fields that attract heavy read traffic such as custom fields.

Large replication lags¹ make the replicas unusable for our services and increases load on the source. Consequently, ensuring that replication lag stays under acceptable limits is a critical SRE requirement.

ALTER TABLE for large tables

Our MySQL databases are such that while the source allows parallel transactions in many cases, all the transactions on the replicas are serialized.

Consider the following transactions, including an ALTER TABLE , executing on the source:

Transactions running in parallel on the source.

The same transactions are executed in the replicas one after another, in order of their commit time on the source:

Serialized transactions on a replica

As indicated in the diagrams above, due to serialization of transactions on the replicas, Txn-3, which was committed a few milliseconds after 05:00 hrs in the source gets committed in the replica only after 05.20 hrs.
Find Largest table size in MySql
Tags: MySQL, Database, Sql

Sometimes you need to know the largest table to know what you need to purge for your database sanity.

Here you go. :)

SELECT [enter table name ] AS `Largest Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`

FROM

information_schema.TABLES

WHERE

TABLE_SCHEMA = “[enter database name]”

ORDER BY

(DATA_LENGTH + INDEX_LENGTH)

DESC;SELECT [enter table name ] AS `Largest Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`

FROM

information_schema.TABLES

WHERE

TABLE_SCHEMA = “[enter database name]”

ORDER BY

(DATA_LENGTH + INDEX_LENGTH)

DESC;

We are reading the information from the information_schema database which is what MySQL uses to manage all metadata about databases in the server.

Happy Coding.
MySQL 서버 PID 파일을 찾을 수 없습니다! 에러. 맥북에서 my.cnf 파일 찾는 법:
Tags: MySQL, 마이시퀄, Mysql Server, Pid File

맥북에서 my.cnf 파일 찾는 법:

mysql --verbose --help | grep my.cnf

2. cd /etc 폴더에 들어간 다음

3. my.cnf 파일 열기

nano my.cnf

4.

mysql 시작/중지 하기:

brew services start mysql

brew services stop mysql sudo /usr/local/Cellar/mysql/8.0.22/support-files/mysql.server start

sudo /usr/local/Cellar/mysql/8.0.22/support-files/mysql.server stop

MySQL에 8080을 통해 접속하는것 실패…

터미널에 sudo mysql -u root -p 라고 치고, 패스워드 넣음

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

라고 뜸.

근데 패스워드 안 넣고 그냥 엔터키 치니까 Welcome to the MySQL monitor이라고 뜸.

mysql -h localhost -P 8080 -u root -p

패스워드 안 넣고 그냥 엔터.

lsof -i tcp:8080 라고 치면 find which process 가 8080를 쓰고 있는지 알 수 있다. 그리고 나서 kill -9 <PID>를 치면 프로세스 종료 가능.

결국 mysql 재설치…:

여전히 에러는 뜨는구나 ㅠㅠ :
Pgloader vs. DBConvert — Migrate from MySQL to PostgreSQL
By: Dmitry Narizhnykh
Tags: MySQL, Postgres, Converter, Postgresql, Database Migration

Migrating data between different types of databases is not a trivial task. In this article, we will compare several ways of converting from MySQL to PostgreSQL.

Essentially, both MySQL and PostgreSQL are relational databases. But why is there a problem at all?

You might be thinking the path is as easy as the three quick steps below.

1. mysqldump --compatible=postgresql > data.sql 2. some_script_that_transforms_mysql_to_postgres_syntax.sh data.sql data.psql 3. psql -f data.psql

It was possible to set the value of “ — compatible” option to in old MySQL 5.7. This option was used for the generation of output that is more compatible with PostgreSQL servers.

Since MySQL 8, according to documentation , that won’t work. The postgresql value is not supported anymore.

Actually, it was impossible to get a PostgreSQL compatible dump file even in the old MySQL 5.7 mysqldump. Several Github Repos contain scripts that perform the second step of converting a MySQL dump to PostgreSQL format. But most of them are now dead.
How to sync your local MySQL schema with Server schema Quickly
Tags: MySQL, Database, Xml, PHP, Schema

I have been using MySQL for many years. It is always a challenge to safely make changes to your production database schema during each release.

The Problem:

Normally what we used to do is to create an SQL script ready and during the release, we will run the SQL script. The issue is by doing this is during our busy development we may miss some columns & it will break our code :(

Solution:

The solution to this problem is to use any MySQL Sync tools like SQL Examiner, dbForge, etc. And most of the tools are PAID.

MySQL Scheman:

MySQL schema, a simple MySQL schema synchronization utility tool which is built in PHP and it is open source. This will create an UPDATE/ADD query automatically based on the schema difference in the database and schema file and it will update schema accordingly.

Installation:

If you use Composer, you can install MySQL Scheman with the following command: composer require smart-php/mysql-scheman

Or alternatively, include a dependency for MySQL Scheman in your composer.json file. For example

{

"require-dev": {

"smart-php/mysql-scheman": "dev-master"

}

}

Basic Usage:

The first step is to create a config file either in JSON or XML where you can put it to database configuration. Next, you can create a schema file and add your required table and field information.

config.xml

<config>

<hostname>127.0.0.1</hostname>

<username>root</username>

<password>mypassword</password>

<database>test</database>

<driver>pdo</driver>

</config>

myscheman.xml

<?xml version="1.0"?>

<database name="shcool">

<table name="students">

<columns Field="id" Type="int(11)" Null="NO" Key="PRI" Default="" Extra="auto_increment" Comment=""/>

<columns Field="name" Type="varchar(255)" Null="NO" Key="" Default="" Extra="" Comment=""/>

</table>

<table name="teachers">

<columns Field="id" Type="int(11)" Null="NO" Key="PRI" Default="" Extra="auto_increment" Comment=""/>

<columns Field="name" Type="varchar(255)" Null="NO" Key="" Default="" Extra="" Comment=""/>

</table>

</database>

Sync

By running the sync command MySQL Shcheman will find the changes required in your server and create an SQL Query and it will execute. In the above example imagine if your database doesn't have table teachers. With sync, it will create a table in the database with fields mentioned in the schema file.

./vendor/bin/scheman --config config.xml --sync myscheman.xml

Reverse Engineering

For existing database structures MySQL Scheman supports reverse engineering of your current database schema. By using command export you can create myscheman.xml file with your existing database.
Basic MySQL Functions
Tags: MySQL, Programming, Coding, Software Engineering, Servers

Below are some of the mysql functions I used
Make Duplicates Unique(SQL)
By: Abhinaya Pabbisetty
Tags: MySQL, Problem Solving

In this article, we will discuss an interesting scenario that you can come across while handling databases and how to approach it.

There is a table comprising orders made by every customer for a shopping portal in the database.

Orders

ID | customerID | displayID | Amount | transactionID | createdAt | updatedAt

3330 | 1003 | 5 | 499 | TR3330–1003 | 2019–09–05 12:38:55.694047 | 2019–09–05 12:38:55.694047

3331 | 1001 | 3 | 499 | TR3331–1001 | 2019–09–05 12:38:55.694047 | 2019–09–05 12:38:55.694047

3332 | 1001 | 3 | 856 | TR3332–1001 | 2019–09–05 12:38:55.694047 | 2019–09–05 12:38:55.694047

For Security reasons, we display orders information using the display ID in web pages. Due to a bug in the system, for a customer multiple orders are created with same display ID.

As per functional design, displayID will always be unique for orders made by a single user. So, some of the orders with the same display Id are never rendered to customers.

To rectify this situation, we should add a unique constraint on customerID and displayID combination in the database. Before that we must first make these displayID duplicates unique per customer in the table.

You have a customer complaining about missing orders and your team has trusted you with this task.

Expected Output:

After executing the solution for fixing duplicates, unique constraint on customerID and displayID combination should be added successfully.

Solution:

Firstly, identify the customerID and displayID combinations that have duplicates and the count of how many such duplicates are present.

select count(displayID) c,displayID, customerID from orders group by customerID,displayID having c > 1

In the above example customerId = 1001 and displayID = 3 , has two duplicates. So if the displayId of one entry is modified, they are no longer duplicates.

To assign a new displayID, we will find the current maxDisplayID in the orders table for that customerID. Let this value be

max_display_id.

select max(displayID) as max_display_id from orders where customerID = ?

If there are n duplicates for [customerId,displayID] combination, we iterate n-1 times

re-assigning displayId = max_display_id + 1 at that instant.

The below ruby script implements this solution.
How to calculate weekly and monthly average in MySQL and visualize over Grafana
By: Shubham Khairnar
Tags: MySQL, How To, Non Time Series, Data, Grafana

Now to visualize a simple graph like above with some non-time series data in it. Be there with me till last!

Step-1:

Open your Grafana UI, ensure you have MySQL Data Source configured and connection: OK

MySQL as Datasource

Step-2:

Create a new dashboard and move to add new panel.

Select configured MySQL database as datasource from left.

Selected MySQL as Datasource

Step-3:

Toggle to text edit mode by clicking on pencil icon.

Text edit mode

Step-4:

For Weekly average, write below query in the space:

Step-5:

You will get some graphs visualization on the screen, else tap on “zoom to data” option on the screen.

Step-6:

Move to Axes part and select mode as Series and choose your value from dropdown i.e. Avg.

X-Axis as Series

Step-7:

Name the graph and save to see final results.

Step -8:

Repeat the procedure for Monthly average with following query:

Step-9:

You can see panels as below in the dashboard:
How to improve performance of MySQL 5.7 with default configuration using Releem
By: Roman Agabekov
Tags: MySQL, Performance Management, Development, DevOps, Servers

In this article, we benchmark the performance of MySQL 5.7 default configuration against the configuration recommended by Releem.

For this benchmark we use Sysbench utility and the server with the following configuration:

Operating System: Debian 9; CPU: 2 cores; RAM: 2GB; MySQL version: 5.7

Benchmark was conducted with the following stages:

Prepare database for benchmark using the following command:

sysbench --db-driver=mysql --mysql-user=root --mysql-password='root' --mysql-db=test

--mysql_storage_engine=innodb --table_size=10000000 --tables=2 --threads=2 /usr/share/sysbench/oltp_read_write.lua prepare

2. Launch test1 (read-only) using the following command:

sysbench --db-driver=mysql --mysql-user=user --mysql-password='password' --mysql-db=test --mysql_storage_engine=innodb --table_size=10000000 --tables=2 --threads=2 --time=60 /usr/share/sysbench/oltp_read_only.lua run

3. Launch test2 (read/write) using the following command:

sysbench --db-driver=mysql --mysql-user=user --mysql-password='password' --mysql-db=test --mysql_storage_engine=innodb --table_size=10000000 --tables=2 --threads=2 --time=60 /usr/share/sysbench/oltp_read_write.lua run

4. Launch Releem Agent and apply recommended MySQL configuration.

5. Launch test1 (read-only) the same as in stage 3.

6. Launch test2 (read/write) the same as in stage 4.

You could see the benchmark results for two MySQL configurations and performance improvments in original post.

Conclusion

The benchmark results reveal that the recommended configuration delivered a 30% boost to MySQL performance compared to the default configuration. In just 1 minute we got the optimized MySQL configuration, which helped us to get a significant performance boost, not only on read workloads but also on a high read/write workload.
MySQL 8.0.22 | Select Order By (ASC, DESC)
By: Student Kim
Tags: MySQL

O rder by — The clause that can put tuples by certain orders.

[Order By]

There are few ways to use order by, but today I’m going to show you the main two of them.

(1) ASC

You can use ASC when you want to return the data in ascending order.(1,2,3…)

select select_list from tableName order by columnName asc;

(2) DESC

DESC stands for descending. (…3,2,1)

select select_list from tableName order by columnName desc;

[Practice Questions]

As always, you can copy and past the query down below, but let’s try to solve the problems by your self as much as you can. I bet you can do that!

create table user(

id int primary key,

name varchar(8),

point int

); insert into user values

(1,'Nina',800),

(2,'Tom',600),

(3,'Amy',800),

(4,'Jake',600),

(5,'Lisa',200); ***Result***

mysql> select * from user;

+----+------+-------+

| id | name | point |

+----+------+-------+

| 1 | Nina | 800 |

| 2 | Tom | 600 |

| 3 | Amy | 800 |

| 4 | Jake | 600 |

| 5 | Lisa | 200 |

+----+------+-------+

5 rows in set (0.00 sec)

Q1. Return all members information by their point in ascending order.

mysql> select * from user order by point asc;

+----+------+-------+

| id | name | point |

+----+------+-------+

| 5 | Lisa | 200 |

| 2 | Tom | 600 |

| 4 | Jake | 600 |

| 1 | Nina | 800 |

| 3 | Amy | 800 |

+----+------+-------+

5 rows in set (0.00 sec)

You can put asc at the end, but the default order by is asc, so it’s fine if you didn’t.

Q2. Return all the members information by their id in descending order.

mysql> select * from user order by id desc;

+----+------+-------+

| id | name | point |

+----+------+-------+

| 5 | Lisa | 200 |

| 4 | Jake | 600 |

| 3 | Amy | 800 |

| 2 | Tom | 600 |

| 1 | Nina | 800 |

+----+------+-------+

5 rows in set (0.00 sec)

Q3. Return members id, name, point by their point in ascending order, but if there are same point, put them by id in descending order.

mysql> select * from user order by point asc, id desc;

+----+------+-------+

| id | name | point |

+----+------+-------+

| 5 | Lisa | 200 |

| 4 | Jake | 600 |

| 2 | Tom | 600 |

| 3 | Amy | 800 |

| 1 | Nina | 800 |

+----+------+-------+

5 rows in set (0.00 sec)

If you need more than one order, you can simply add ,column asc/desc at the end. The first column after by is the main order, and the second is the next one.

Today was very simple right? On my next session I’ll bring some more clause that you can use with select statement as well. Thanks guys see ya!
Create SQL from CSV files for larger updation or insertion
By: Avinash Dalvi
Tags: MySQL, Regex, Sql, Technology, Sublimetext

Few days back I came across one problem where I have to create a bulk update script based on a given CSV or Excel file. First I thought of finding something in excel level by writing some macros or functions.

Then my friend helped me to use the easiest method using a sublime text editor. Would like to know about this approach ?

As I said above It’s simpler to create and update scripts. Let’s take an example I have below CSV filecontent.

mumbai,avinashdalvi@test.com

thane,avinash@malinator.com

bangalore,test@mailinator.com

Follow below steps :

Open CSV file in sublime text editor. Open Replace toolbar from Menu -> Find -> Replace ( You can directly open by short command Option+Command+F for Mac user, Control+Shift+F for Window or ubuntu user. Enable regex option in toolbar ( It will look like .*). You can see 👇🏻 below image. Considering two fields in CSV, write (.*),(.*) in the Find field on the toolbar.

update table tablename set fieldname1 = '$1' where fieldname = '$2' in Replace field. $1 stand for first field and $2 stand for second first. Vice versa if you have multiple fields you can mention $3 and so on. Try to click on the find button and check whether it is highlighting properly or not. Then you click on “Replace All” and see this output.

Output :

Update tablename set fieldname1 = 'mumbai' where fieldname = 'avinashdalvi@test.com'; Update tablename set fieldname1 = 'thane' where fieldname = 'avinash@malinator.com'; Update tablename set fieldname1 = 'bangalore' where fieldname = 'test@mailinator.com';

Note : You can write any other SQL like insert or delete to create a SQL script. This is a little hack which can help to save time while creating a script when you are dealing with more numbers of records.

Hope this helps you. Thanks for reading this blog. If any feedback feel free to reach out to me.
DockerのMySQLでコマンド操作を行う
Tags: MySQL, Docker

dockerで立てたMySQLでコマンド操作を行うには以下の２種類の方法があります。

dockerコンテナ内に入り、mysqlコマンドを実行する

tcp経由でmysqlコンテナがマウントしているポートから接続する

ひとつずつ見ていきましょう。

事前準備

既に接続したいmysqlコンテナがある場合は読み飛ばしてください。

mysqlのdockerコンテナを起動する

$ docker run --detach --name sample_mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=1 mysql:5.7 docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

2d2723f178fa mysql:5.7 "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp sample_mysql

【方法１】dockerコンテナ内に入り、mysqlコマンドを実行する

1. docker exec コマンドでコンテナ内に入ります

$ docker exec -it sample_mysql bash

2. コンテナ内でmysqlコマンドを実行します

# mysql -u root -h localhost -P 3306

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.30 MySQL Community Server (GPL)

​

Copyright © 2000, 2020, Oracle and/or its affiliates. All rights reserved.

​

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

​

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

​

mysql>

この場合は localhost の代わりに 127.0.0.1 でもログインできます。

【方法２】tcp経由でmysqlコンテナがマウントしているポートから接続する

mysqlコマンドを直接実行します（方法１ではコンテナにインストールされているmysqlコマンドを仕様しましたが、方法２ではPCのmysqlコマンドを使用するため、インストールされていない場合は実行できません）

$ mysql -u root -h 127.0.0.1 -P 3306

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.7.30 MySQL Community Server (GPL)

​

Copyright © 2000, 2020, Oracle and/or its affiliates. All rights reserved.

​

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

​

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

​

mysql>

はい、接続ができました。１コマンドで行けるのは楽ですね。

ここで注意して欲しいのが、 127.0.0.1 を localhost にした場合は接続ができません。

$ mysql -u root -h localhost -P 3306

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

localhost の場合はtcp通信ではなく、UNIXドメインソケットを利用した通信を行うようです。dockerコンテナはtcpポートに対してマウントしているので、UNIXドメインソケットでリクエストしてもdockerコンテナには繋がりません。（windowsはわからん）参考

なので、 localhost にしたい場合はコマンドのオプションで明示的にtcpを指定します。

$ mysql -u root -h localhost -P 3306 --protocol=tcp

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.7.30 MySQL Community Server (GPL)

​

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

​

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

​

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

​

mysql>

繋がりました🎉🎉

ソケットに関してはこの辺の記事が参考になりそうです。

それではみなさん、良いHappy Docker Ligeを！！👋
How to handle MySQL database transactions with NodeJS
By: Sehan Rathnayake
Tags: MySQL, Programming, JavaScript, Database, Nodejs

How to handle MySQL database transactions with NodeJS

MySql with NodeJS

Transaction Management in javascript is required when we are dealing with relational databases such as mySQL. By using transactions we can group SQL queries so that we can commit them when all the queries runs fine. If we get any exception, we have the choice to rollback all the queries.

In this tutorial we use mysql2 MySQL client for NodeJS. So our package.json file will be like this.

For this Tutorial we use two simple MySQL tables named STUDENT and ADDRESS. Below is the DDL to create those two tables.

Then we will create a method to add student. This method will add entry into STUDENT table as well as into ADDRESS table. First will do this without considering transactions.

Difference between execute and query method

Here we have use execute method in mysql2. You have the choice to use either of execute or query methods.The main difference of those two methods is in query method parameter substitution is handled on the client side where in execute method prepared statement parameters are sent from the client as a serialized string and handled by the server.

Use of connection pool

We have created a connection pool in this example. When you are doing multiple data manipulations it is better to create a connection pool and reuse the connections rather than creating connections for each and every request.

Let’s try to understand what is going on. What addStudent (studentId,name,address,city) method does is, it add entry to STUDENT table and if it is inserted successfully it will add entry to ADDRESS table. We have added two entries using that method, first with valid values and the second is with invalid value for CITY column.

After the two method calls tables in the database will look like this.

We can see that even though that the insertion for ADDRESS table failed for student Michael Smith , the entry in the STUDENT table is still there. Assume that our requirement is to create users with address and we don’t want to have any entries for students without the address. In that situation we have to rollback the first query if the second query fails.

Let’s implement same method with handling transactions.

After the two method calls tables in the database will look like this.

We can see that since the insertion to ADDRESS table failed for student Michael Smith insertion to the STUDENT table has been rollbacked. So we won’t have any student entries without the address.

Don’t forget to release the connection after using

It is better to avoid using pool.getConnection() unless it is necessary. In first example we didn’t use that method. But when there are multiple queries to be executed within a transaction we have to use pool.getConnection() method.

If you call pool.getConnection() , you must call connection.release() when you are done using the connection. Otherwise connection won’t be returned to the pool and the application will get stuck after it hits the connection limit.
Select Inner Join + Basic Exercise Questions(Table Nickname)
By: Student Kim
Tags: MySQL

Join — The clause which combine tuples from tow or more tables, based on related columns between them.

As you see, we’re going to learn the Join today. You might think “After all those hard works with foreign key, and now you want me to combine tables back? What the…….” I feel you.

But, we need join to read those data easily! And we can use join even on the tables without foreign key. There are two joins, Inner and Outer. Today I’ll be talking about the Inner Join.

[Inner Join]

Inner Join can combine tuples that have same value of certain columns.

And there are two ways to use it.

(1) Basic Inner Join

The basic query of the inner join is

select table1.column1, table2.column2

from table1

inner join table2

on table1.column=table2.column;

On the first line, there are column1 from table1 and column2 from table2 that you want to select, and it can be one or more. The columns after on are the columns that related to each other. But I prefer the next one because the basic one is bit complicated.

(2) Second Query
How to add multiple columns after a specific column quickly in MySQL?
By: Winchester Allpesh
Tags: MySQL, Intellij, After A Specific Column, Alter Table, Multi Column

So, I got struck with a problem statement where I had to add too many columns around 20–30 columns after a column in a table. This is where all it started.

At first, I googled if is there any solution to that? And I found this on the StackOverflow.

Original question:

I need to add multiple columns to a table but position the columns after a column called lastname .

I have tried this:

ALTER TABLE `users` ADD COLUMN

(

`count` smallint(6) NOT NULL,

`log` varchar(12) NOT NULL,

`status` int(10) unsigned NOT NULL

)

AFTER `lastname`;

Unfortunately, this doesn’t work as it’s syntactically incorrect in MySQL dialect.

So the right way to do this is using ADD command with AFTER every time for each column like this:

ALTER TABLE users

ADD COLUMN `count` SMALLINT(6) NOT NULL AFTER `lastname`,

ADD COLUMN `log` VARCHAR(12) NOT NULL AFTER `count`,

ADD COLUMN `status` INT(10) UNSIGNED NOT NULL AFTER `log`;

Took this ^ from the accepted answer.

This will be OK if you need to add only 3–4 columns but will be super boring if you need to add let say 20–30 columns.

Final Solution (Using multi cursor selection and multi edit):

Nowadays, every IDE supports multi cursor selection. I’ll be using IntellJ IDE here to explain the solution:

In short:

Longer version:

Step 1: Prepare all the columns you want to add

For example this:

ALTER TABLE `users` ADD COLUMN

(

`count` smallint(6) NOT NULL,

`log` varchar(12) NOT NULL,

`status` int(10) unsigned NOT NULL

)

Step 2: Take your cursor just after the comma and select the new line.

Step 3: Multi cursor selection.

Step 4: Select and multi-copy last two.

Step 5: Go to the next line just before comma and type “AFTER” and then paste it.

And you’re done.
MySQL Quick Reference (Syntax Version)
By: Jayesh Rao
Tags: MySQL, Database, Dbms, Sql, Data

ACID properties:

Atomicity: All or None, if the transaction fails in between, it rolls back entirely.

Consistency: If the transaction has occurred between two parties, then it should reflect on both sides.

Isolation: If multiple transactions are running concurrently, they should not be affected by each other.

Durability: Hardware and Software failure must not cause the data loss during transaction.

DML: insert, update, delete, merge

DDL: Create, drop, truncate: deletes all the rows (where cannot be used), alter, rename.

DQL: select

DCL: grant, revoke

TCL: commit, rollback, savepoint- sets savepoint within transaction.

Operator order of precedence: SQL will always give higher precedence to AND followed by OR.

Wild Card Characters: % for sequence of characters, _ for a single character and * to select everything.

Syntax:
Setup WordPress Application using Amazon RDS on backend
Tags: MySQL, Aws Rds, Kubernetes, WordPress, Terraform

To begin with, we have a new concept here, i.e., AWS RDS. Amazon Relational Database Service is a distributed relational database service by Amazon Web Services. It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications. All major database servers like MySQL, PostgreSQL, MariaDB, Oracle, etc can be deployed as database instance on RDS. We would be using MySQL database server on the backend of the application.

As the frontend of WordPress application, we would run the application as a deployment-service on Kubernetes running on a Minikube Workstation. Frontend would be running on local workstation and backend would be running on AWS, thus creating a hybrid-cloud architecture.

Note: The article does not cover the installation of minikube, which is a pre-requisite. However, check on the official websites for installation: https://kubernetes.io/docs/tasks/tools/install-kubectl/ https://kubernetes.io/docs/tasks/tools/install-minikube/

Automation implementation — The deployment would be done using Infrastructure As A Code (IAAS) using terraform. Practically, one single command will be able to setup the whole architecture and redirect the browser to the application IP.
MySQL 8.0 ERROR 1045 (28000) 問題處理
Tags: MySQL, Error 1045

MySql 是一套免費且輕量的資料庫系統，教學/自用兩相宜，兩次MAC因故非正常關機，再重新啟動後MySql不認我這個主人了…

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO) ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

我真的不是故意的，上課學習跟專題的資料都在裡面啊啊啊啊啊，不要這樣對我(倒 T_T)

第一次發生時有點慌，資料不多所以砍掉重裝，這回是第二次發生了，拜一下Google冷靜觀察後似乎還有救，反正死馬當活馬醫，雖然這次是救回來了但每次狀況不一定相同，保持良好的使用習慣避免資料庫發生問題會比較好

這邊提醒一下，我使用的MySql是8.0，網路上有些比較早期的心得文，處理方式並不適用於這版MySql，但對於了解MySql環境的基本概念還是有些幫助

ERROR 1045 (28000) 這個問題基本上就是root的密碼不知為何已經無法判斷並登入，所以處理方式就是去把root的密碼重新設定(修改)一次

1.開啟mac的終端機，用ps這個指令查看mysql的服務是不是還在運作

ps -ax|grep mysql

2.如果mysql還再先把 mysql 停掉，以上圖為例mysql的服務還在運作且看得到它的PID是1851，所以用kill的指令把它清掉，記住看清楚PID且輸入正確不要刪錯了，如果mysql沒有在運作，那就不用進行這個步驟

kill 1851

3.以下列的方式啟動mysql(不用輸入root密碼)，mysql會跑起來這樣就能查看與調整系統資料表的內容

mysqld_safe --user=mysql --skip-grant-tables --skip-networking

4.再另外開一個新的終端機視窗，注意，是另外開一個終端機視窗，不是在剛剛啟動mysql那個終端機的視窗操作，用以下指令進到mysql的command mode

mysql -uroot mysql

5.可以下sql指令觀察目前系統資料表中的帳號

mysql>select user,host,authentication_string from user;

6.下sql指令清空 root 的密碼，這步下去就無法回頭了，要不要賭一把救救自己的MySql要考慮清楚，還有WHERE條件不要打錯，清到不該清的事情會更大條

UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';

7.離開mysql的command mode，輸入 exit 或 quit 都可以

mysql>exit

8.停止mysql的服務，這時因為root的密碼已經被清空，所以改用指令來停止它，當然要用之前kill的方式也不是不行，這邊我選擇用指令，看到Shutdown Complete的訊息讓人比較安心

mysqladmin -u root shutdown

9.在之前啟動mysql服務的那個終端機視窗，以一般的方式啟動mysql，這邊我是用mysqld去啟動它

mysqld

10.回到清掉root密碼的那個終端機視窗，再次登入MySql 的command mode(目前不需密碼了，因為剛剛把密碼清掉了)

mysql -uroot mysql

11.用alter的指令修改root的密碼，這邊我是把密碼改為 “password”

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

12.下指令讓改變使用者(root)的動作更新到mysql裡

mysql> FLUSH PRIVILEGES;

13.大功告成，離開MySql 的command mode(這次改用quit離開)

mysql> quit

祝 大家的MySql頭好壯壯，永不當機。

我是布魯斯，蒼海中的藍色工程師

參考網路上大神的資料：

https://www.itread01.com/content/1549049422.html
How to Setup SSL Certificate to Use on a Local Magento 2 Site
By: Malik Elgabroun
Tags: MySQL, Programming, Magento 2, Nginx, Magento

Setup

To add an SSL certificate to our local environment we would first need to generate the certificate keys for the specific project using OpenSSL by running the following command in the terminal. Note: you can call the key whatever name you want.

openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes -out projectname.crt -keyout projectname.key

Upon running the command, you will be presented with a couple of questions. As you can see from the screenshot below, you can answer them with generic answers that do not need to be related to the actual project as long as they are filled.
Server Side Pagination in Node.js Angular 10 + MySQL + Sequelize
Tags: MySQL, Angular, Nodejs, Pagination, Server Side

In the tutorial, I introduce how to build an “Angular 10 Nodejs Pagination RestAPIs Example with MySQL database (Server Side Pagination with filtering and sorting)” project using Express framework and Sequelize crud queries to interact with database’s records.

– Nodejs Express project (server side pagination) produces pagination RestAPIs with MySQL database records using Sequelize CRUD queries.

– Angular 10 project (client side pagination) will consume the Node.js pagination RestAPIs then show up on component’s views.

Architecture Design Angular Node.js Application

In the tutorial “Server Side Pagination in Node.js Angular 10”, We develop 2 projects:

Backend Project — Nodejs MySQL Pagination Application gets data from MySQL database then provides RestAPIs with pagination, filtering and sorting function for frontend

Frontend Project — Angular Application use HttpClient to fetch data from Backend Application then shows them in Bootstrap table with pagination, filtering and sorting functions

Goal

– Make a request at API: /api/customers/pagefiltersort with pagination, filtering and sorting params as below:

page : 0 – first page

: 0 – first page size : 5 – size of a page

: 5 – size of a page salary : 4000 – filtering by salary field

: 4000 – filtering by field agesorting : true – sorting by age

: true – sorting by age desc : true – descending or ascending sorting

Sourcecode

Tutorial Link
Tech talk in 2021
By: Paolo Cuomo, Talks Tech
Tags: Quantum Computing, Insurtech, STEM, Sustainability, Quantum

Tech talk in 2021

Photo by Estée Janssens on Unsplash

So, a number of topics for this year.

Quantum

Clearly I’ll be pushing ahead the Quantum London agenda, with webinars, podcast and (hopefully) in person events. Where relevant this will turn into content here. I’m not a believer that everything should be transcribed. There’s a lot of content in the world already, so I’m aiming for a mix of written, audio, video, infographics etc

InsurTech

Insurtech, sure, how could I not. But frankly it will be more the broader topic of tech-enabled insurance innovation, and the associated thinking around bionic underwriting.

Sustainability

Hopefully this gets back to the front of the agenda this year as it is more important, and more urgent, than just about anything else. The role of tech here is vital and not broadly enough communicated.

STEM/STEAM education

A real interest of mine but one I typically don’t manage to spend as much time as I would like on. Let’s see how 2021 serves this topic.

It is of course a scalable, foundation concept — i.e., the more people we engage, and the sooner we do it, the greater the longer term impact. That view on much of the topic of technology education should be considered when coming up with priorities for focus.

And whatever becomes new and interesting….

I’m so confident that with everything that is happening in the world of tech — deepfake videos, bold aspirations around space, driverless cars, etc etc — that there will be several new topics of interest during the year.
The Step-by-Step Curriculum I’m Using to Teach Myself Data Science in 2021
By: Madison Hunter
Tags: Programming, STEM, Education, Data Science, Machine Learning

The Step-by-Step Curriculum I’m Using to Teach Myself Data Science in 2021

Photo by Pavel Herceg on Unsplash

The end of December is the perfect time to make plans and resolutions for the upcoming new year. For some, resolutions include joining a gym, learning a new language, or reading fifty books.

As for me, my new year’s resolution is to learn data science. Because I like a challenge, I want to learn data science without spending a single penny.

Thanks to the generosity and ingenuity of many current data scientists, the internet is teeming with free learning resources covering every minute detail of data science. From learning how to code using Python, to learning multivariable calculus, to learning how to develop machine learning algorithms, it’s now possible to become a competent and competitive data scientist without spending thousands of dollars or years of your time on a post-secondary degree, diploma, or certificate.

There is no better time than a new year to challenge yourself and develop new skills. Plus, if the pandemic has taught us anything, it’s that upskilling is never a waste of time and can help guarantee you better employment options.

Data science is becoming one of the sexiest tech fields to get into, with low unemployment rates and nearly guaranteed job security. Furthermore, data science touches every single industry you could think of, including medicine, the military, business, science, education, government, and tech. In other words, you can learn data science techniques and apply them to whatever field inspires you or that you already have experience in. What’s there not to like?
An Hour of Code during Computer Science Week
By: Coralie Fond Hentsch
Tags: Computer Science, Hour Of Code, Coding, STEM, Lessons

Computer Science Week happening Dec. 7–13, 2020 aims to inspire K-12 students to learn computer science through various activities and the Hour of Code. Participate with CoSpaces Edu and let your kids code their own creation!

CoSpaces Edu lets kids learn to code with its visual block-based language CoBlocks by having fun creating anything they like in 3D!

If you haven’t yet, simply create a free account on cospaces.io/edu and access CoSpaces Edu directly in your desktop’s browser (no download needed!) or on a mobile or tablet device with the CoSpaces Edu mobile app.

Learn more about the CoSpaces Edu coding features.
MULHERES NA FÓRMULA 1: Conquistas e lutas
By: Camila Mendonça De Freitas
Tags: STEM, Girls, Feminismo, Feminism

I am a young woman willing to live new experiences that can contribute to my professional growth. Chemistry researcher but writer in mean time.
Promoting STEM Education at Clintonel Innovation Center (CIC)
By: Clintonel Innovation Centre Cic
Tags: STEM, Clintonel

Most jobs of the future will require a basic understanding of STEM as technology is rapidly expanding into every aspect of our lives.

STEM education produces critical thinkers, increases science & technology literacy and enables the next generation of innovators

At Clintonel Innovation Centre (CIC), we expose students to STEM and give them opportunities to explore STEM-related concepts.

#clintonel

#STEM
University of Georgia Joins IChange Network As Part of an Effort to Improve Diversity of STEM Faculty
By: Jaymie White
Tags: STEM, University Of Georgia, Diversity, Education

University of Georgia Joins IChange Network As Part of an Effort to Improve Diversity of STEM Faculty Jaymie White Follow Dec 21, 2020 · 1 min read

The University of Georgia (UGA) has started a survey to gather input on the recruitment and retention of diverse STEM faculty. It is one of the first steps in increasing faculty diversity and using inclusive teaching models in STEM fields. According to Gregory Robinson, a chemistry professor and the lead faculty member coordinating the university’s participation in the IChange Network, they are evaluating their past efforts to determine how they can move forward in recruiting and retaining diverse STEM faculty.

https://suppliertynews.com/2020/12/21/university-of-georgia-joins-ichange-network-as-part-of-an-effort-to-improve-diversity-of-stem-faculty/
Living in Fear
By: Chia-Yi Hou
Tags: Immigrant Stories, Graduate School, Phd Student, PhD, STEM

At 28, I had finally begun to peel away at the layers of my life. I started to understand not only who I was, but what my priorities were, where my interests lay and what I could do.

I was born in a small European country, a year before a violent civil war began. My family fled and eventually settled in California. As far as I can remember, I was a content child. Still, the fundamental theme of my family’s early household was one of survival.

There were no cousins, no aunts, no uncles. There were neither grandparents nor close family friends. There were few summer camps or trips to the mountains or lakes or beaches. At school, I would hear of plans of Thanksgiving and family reunions. I heard crisp, perfect English. At home, it became more difficult for me to understand the language my parents spoke in. It seemed like such a small thing — no family gatherings, no connection to any place, just my small family and me. It was my life and it seemed alright, I did not think much of it.

Yet, like raindrops trickling down a window, small things accumulated in such a way that I seldom realized how deeply I internalized the idea that I was different. I was neither like the community to which my peers belonged nor to the community in which my parents grew up in. I felt unformed on two fronts.

A hollowness began to grow inside of me. The feeling was remote, so omnipresent I would almost forget about it, a dull pain I taught myself to ignore. Other times, it would suddenly balloon inside of me, occupying a space so large that it would press up inside of me, truly hurting.

My brain became compelled to understand my emotion and label it, so that I could overcome it. But whenever I reached for language, as I am trying to do now, to communicate, analyze or question, my mind would feel slippery. I would return frightened, wondering if maybe there was nothing there to explain, if maybe this was all just a part of who I was. The thought shocked me.

Like a single drop of ink turns clear water black, entrenched feelings of a lack of belonging diffused inside of me and took over. Like all of us, I had an inherent need to be accepted as part of a group larger than myself. When that was not fulfilled, it came with consequences that manifested themselves, in my case, as ingrained self-deprecating thought patterns.



I felt stupid for not being fluent in my parents’ native language, despite having been born there. I felt stupid when my family never had vacation plans or visiting relatives. I felt stupid when, at 19, I didn’t know how to pitch a tent on my first camping trip, with everyone around me talking about how the had been camping “all their life.” Mostly, I felt stupid as I saw many of my peers fall into and excel at hobbies or professions they had picked up from a family member, found at a camp or through a family friend, something they had the capacity and opportunity to be exposed to and to explore.
How to improve Kids Skill with STEM Learning Toys !!
By: Switched On Kids
Tags: STEM, Stem Education, Education Technology, Science Experiment

How to improve Kids Skill with STEM Learning Toys !!

STEM Toys

STEM Amusement Park Set — London Eye & Ferris Wheel teaches about these wonderful places where children and adults spend countless hours of fun worldwide! This set includes one geared motor to power four large-scale models of amusement rides: Ferris wheel, London Eye, merry-go-round and booster ride. The set comes in a convenient plastic storage tub with lid for easy storage.

Additionally, you can experiment with gears by building four smaller models such as a gearbox, an experimental crane, a carousel and a planetarium. You can find easy-to-follow building instructions for all models either online or in the booklet included. The booklet provides detailed explanations of the different scientific principles applied and incorporates innovative experimental activities for hands-on learning. A Quiz section is also available to challenge your newly acquired knowledge!

STEM Amusement Park Set — London Eye & Ferris Wheel : ENGINO TOY SYSTEM is perhaps the most advanced and versatile three dimensional construction toy in the market today! What makes this product so unique is the variety of innovations in functionality and efficiency. The patented design of the parts allows snap-fit connectivity of up to 6 sides simultaneously!
Chemistry, Oh Chemistry…
By: Stem Response Wlv
Tags: STEM, Chemistry, Science, Christmas

It’s one of the oldest stories: a baby born under a bright shining star, shepherds and wise men travel far to meet them, bringing gifts. Two of these infamous gifts were Frankincense and Myrrh. But, what are these legendary items, and why were they such lavish gifts?

Courtesy of Mental Floss.

What is Frankincense?

Frankincense, which is otherwise known as Olibanum, is still regularly used today — even though we are less aware of its use. It’s a pale yellow resin that’s extracted from Boswellia trees. The main use of frankincense, as the name suggests, is as a type of incense. It can also be found inside some expensive perfumes and other scented products such as skincare.

When it’s used as incense, a number of compounds are what make the iconic aroma. A significant percentage of the resin is made of compounds called ‘boswellic acids’, but these don’t contribute to the scent, as they are too heavy to become volatile when burned. Instead, a variety of other compounds are found in the smoke: octanol, octyl acetate and various ‘terpenoid compounds’ have all been identified as contributors to the smell of burning frankincense.

Courtesy of Compound Interest.

What is Myrrh?

Myrrh is potentially the least understood of the three gifts. Not unlike frankincense, it is also a resin (red-brown in colour), obtained from Commiphora trees. It was originally used as part of the embalming process in Ancient Egypt, and can also be used in perfumes and as a incense. Myrrh has been used in traditional medicine for many centuries, as studies have shown that it has antibacterial properties.

The smell of Myrrh is attributed to the presence of several compounds from ‘the furanosesquiterpene’ family of chemicals. These include dihydropyrocurzerenone, lindestrene, and furanoeudesma-1,3-diene, with these essential oils being important contributors to the sweet-woody scent.

Are you interested in Chemistry? Perhaps considering a career in Chemical Sciences? Why not check out the Chemistry courses at the University of Wolverhampton: https://bit.ly/3nsuQB3

By Phoebe Hinton-Sheley
List of jobs in tech. I am back. I know it’s been a long…
By: Charmaine Mabika
Tags: Wocintech, Tech, Tech Jobs, STEM, Technology

Hey guys!

I am back. I know it’s been a long time, but this blog post required a lot of time to construct. I get a lot of questions regarding the types of roles there are in tech and what they require. Now this isn’t ALL the jobs in tech and that’s the beauty of this blog post that there’s this list and more jobs. I’ve made it easier for you depending on your interests regarding if its more a creative role, requires coding or a certain skill set. Use this as a guide but not as a bible so feel free to look at other roles that may be out of your current interests or skill set as you never know!

So without further or do, here’s a list of roles in tech! :

Backend engineering