background preloader

Developer Zone

Developer Zone
Related:  mySQL

How to Use JSON Data Fields in MySQL Databases In my article SQL vs NoSQL: The Differences, I mentioned the line between SQL and NoSQL databases has become increasingly blurred with each camp adopting features from the other. MySQL 5.7 InnoDB and PostgreSQL 9.4 databases both directly support JSON document types in a single field. In this article, we’ll examine MySQL’s JSON implementation in more detail. (PostgreSQL supported JSON before version 9.4 and any database will accept JSON documents as a single string blob. Just Because You Can Store JSON … … it doesn’t follow you should. Normalization is a technique used to optimize the database structure. If you have clear relational data requirements, use appropriate single-value fields. That said, there are good JSON use-cases for sparsely-populated data or custom attributes. Create a Table with a JSON Field Consider a shop selling books. a tag table which stored each tag name against a unique ID, anda tagmap table with many-to-many records mapping book IDs to tag IDs Adding JSON Data

Storing JSON data in a database column mysql - What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? Usability problems of mysqli compared to PDO Disclaimer. By no means I am going to say that mysqli is worse than PDO. Mysqli is an excellent extension, with many specific features. But it's just not intended to be used directly. To make it usable, one have to always wrap it into a helper library, to reduce the enormous amount of code that otherwise have to be written by hand. But for the average PHP/MySQL user, standard APIs are the only known methods for database interaction. Note that this article is written out of premise that a query should be consisted of constant values only. Named placeholders To me it's rather a yet another source of confusion (there are thousands questions on Stack Overflow, caused by mere typos in placeholder names), which also makes your code bloated. $stmt = $pdo->prepare("UPDATE users SET name=:name, email=:email WHERE id=:id"); or $stmt = $pdo->prepare("UPDATE users SET name=? while mysqli users have to stick with the latter. General inconvenience in binding $pdo->prepare("INSERT INTO numbers VALUES (?)")

MySQL :: MySQL Workbench: Visual Database Design Visual Database Schema Design MySQL Workbench simplifies database design and maintenance, automates time-consuming and error-prone tasks, and improves communication among DBA and developer teams. It enables data architects to visualize requirements, communicate with stakeholders, and resolve design issues before a major investment of time and resources is made. Forward and Reverse Engineering MySQL Workbench provides capabilities for forward engineering of physical database designs. Change Management Database change management is a difficult and complex process, which involves maintaining different versions of database schemas and manually modifying existing databases. Database Documentation Documenting database designs can be a time-consuming process.

GitHub - damiantw/laravel-scout-mysql-driver: Laravel Scout MySQL Driver Visual Database Creation with MySQL Workbench In today’s tutorial, you’ll learn how to use a visual database modeling utility to draw a database diagram and automatically generate SQL. Specifically, we’ll review how to use MySQL Workbench, a cross-platform, visual database design tool. MySQL Workbench is a powerful tool developed by MySQL with three primary areas of functionality: SQL Development: Replaces MySQL query browser. Allows the user to connect to an existing database and edit and execute SQL queries.Data Modeling: Complete visual database design and modeling.Database Administration: Replaces MySQL administrator. Graphic interface to start/stop servers, create user accounts, edit configuration files, etc. In this tutorial, we’ll focus on the Data Modeling aspect to create a database from scratch, and then have just a quick look at the SQL editor to execute our generated SQL script and create the database within MySQL. MySQL Workbench is available for Windows, Linux and Mac OSX. It’s time to launch Workbench. And that’s it.

themsaid - Laravel/MySQL JSON documents faster lookup using generated columns Back to home laravel 5.3 is shipped with built-in support for updating and querying JSON type database fields, the support currently fully covers MySQL 5.7 JSON type fields updates and lookups, this allows us to have the following: DB::table('users')->where('meta->favorite_color', 'red')->get(); This will bring all users who have a favorite color of red, here's a sample table structure: You may also update the field like that: DB::table('users') ->where('id', 1) ->update(['meta->origin' => 'Asshai']); Matt Stauffer wrote up a post about the new features that you can check here. In this post I'd like to show you how we can achieve faster lookups for data stored in JSON-type fields using MySQL generated columns. As mentioned in MySQL manual: JSON columns cannot be indexed. Let's see how we may create a generated column to store users favorite color for later indexing: ALTER TABLE users ADD meta_favorite_color VARCHAR(50) AS (meta->>"$.favorite_color"); Using database migrations

Export from MySQL Workbench to a Laravel Migration MySQL Workbench is a cross-platform GPL app that allows you to fully design and document your databases through the app. Brandon Eckenrode, created a plugin that allows you to export a MySQL Workbench model to Laravel 5 migrations that follow PSR-2 coding standards. When exported, each migration is generated and saved in its own, properly named, migration file. This works by downloading the plugin from GitHub, then open MySQL Workbench and go to the Scripting menu, Install Plugin/Module. When you open it back up navigate to File -> New Model and add a basic structure for a table. Next, navigate to Tools -> Catalog -> Export Laravel 5 Migration, and a window will open with the migration ready for you to download: You can download this from GitHub and learn about Workbench Modeling on the MySQL site. If you are a Sequel Pro user be sure and check out a similar style plugin, Export from Sequel Pro to a Laravel Migration

GitHub - beckenrode/mysql-workbench-export-laravel-5-migrations: A MySQL Workbench plugin which exports a Model to Laravel 5 Migrations Using MySQL's JSON columns in Laravel 5.3 - murze.be Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Laravel 5.3, which will be released at this years Laracon US, has some new very handy functionality to work with MySQL 5.7 JSON columns. While Laravel has had the ability to cast your data to and from JSON since version 5.0, it was previously just a convenience—your data was still just stored in a TEXT field. If you’re going to use this functionality, you should also read Mohamed Said‘s post on how to improve performance by using MySQL generated columns. JSON columns cannot be indexed. Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel.

How to Optimize MySQL: Indexes, Slow Queries, Configuration MySQL is still the world’s most popular relational database, and yet, it’s still the most unoptimized – many people leave it at default values, not bothering to investigate further. In this article, we’ll look at some MySQL optimization tips we’ve covered previously, and combine them with novelties that came out since. Configuration Optimization The first – and most skipped! – performance upgrade every user of MySQL should do is tweak the configuration. 5.7 (the current version) has much better defaults than its predecessors, but it’s still easy to make improvements on top of those. We’ll assume you’re using a Linux-based host or a good Vagrant box like our Homestead Improved so your configuration file will be in /etc/mysql/my.cnf. Editing Configuration You’ll need to be comfortable with using the command line. Note: modify the above path to match the config file’s real location – it’s possible that it’s actually in /etc/mysql/mysql.conf.d/mysqld.cnf Manual Tweaks Variable Inspector Indexes

Related: