I am using MySQL 8 and was trying to query SELECT DISTINCT with CONCAT on my Linux Mint system. If you have MySQL 5.x, please refer to the official documentations.
Here is the query that worked for me..
SELECT DISTINCT CONCAT( author_fname, ' ', author_lname) as Author FROM books;
A quick PHP, MySQL CRUD operation with PDO mysql driver with minimul HTML and almost no CSS. I am going to share the code for each file and operation separately.
I am using XAMPP server with MariaDB, PHP 8.1, and Apache 2.4 web server on my Windows 10 Pro.
I assume that you are already familiar with XAMPP htdocs and phpmyadmin. I have created a database using phpmyadmin and rest everything in php files.
Create Database and MySQL Connection with PDO
/db.php
<?php
$connect = new PDO('mysql:host=localhost;dbname=phpecom', 'root', 'password');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
Create Profile page
This is where is the create or insert HTML form to insert row data into the database table
I assume that you already have installed MySQL on your Windows operating system and you are trying to access it through command prompt or PowerShell and you are getting this message MySQL is not recognized as an internal or external command, operable program or batch file.
I completely understand why you are getting this message. Basically, we need to add MySQL to the systems variable path.
To add MySQL to the system’s variable path, we need to locate the Bin folder in MySQL installation directory and then add it to the system’s variable path.
I are going to install MySQL server on Ubuntu 19.04 using terminal, but you can follow the instructions and install MySQL server on Ubuntu 18.04 as well.
First thing first, we need to update the system core, so launch your terminal manually or press control+shift+t and type following command..
sudo apt update && upgrade
Wait for the updates and upgradables to be finished and then run MySQL installation command…
sudo apt install mysql-server -y
When MySQL server is installed on your Ubuntu desktop, simply exit out of the terminal and relaunch the terminal and login to MySQL with sudo right.. type –
sudo mysql
Now you in the MySQL ternimal interface, here we are now going to alter root password, so that you can login to MySQL with root username and its password.
Alter MySQL root user password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Here you should choose a secure password for the root user. Now, let’s flush the privileges
FLUSH PRIVILEGES;
Now, exit out of the MySQL interface and log back in with root user and the altered password.
exit
mysql -u root -p
Type root user password and create your very first SQL database with this simple command..
CREATE DATABASE db_name;
Check all the databases, that exist on the SQL database.
SHOW DATABASES;
If you still can’t install MySQL on Ubuntu, you can watch me install MySQL on my Ubuntu 19.04
Hello World!! In this tiny MySQL Tutorial video, I demonstrate how to create a database, select database, create a table, and insert values into the table, using the terminal, command line, prompt.
How to hash the password in MySQL Database.
How to create a database in MySQL CREATE DATABASE database_name; How to list databases in MySQL SHOW DATABASES; How to select a database in MySQL USE database_name; How to create a table in MySQL CREATE TABLE table_name(
ID INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
useremail VARCHAR(80) NOT NULL,
userpassword CHAR(50) NOT NULL,
user_created_at TIMESTAMP);
How to insert values in MySQL table INSERT INTO table_name(username, usermail, userpassword) VALUE('name1', '[email protected]', SHA('secret");
DROP DATABASE mydb;
This is the database drop command is.
Make sure you are logged in the MySQL server MySQL -u -root -p
and then run the database drop command to delete MySQL database using the terminal.