Posts

Showing posts with the label mysql

Reset root password on MySQL on Windows 10 laptop

Stop SQL Server Create a text file "mysql-init.txt" in C:\temp directory and paste in this content ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; Open a command prompt window and run this command mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file="C:\\temp\\mysql-init.txt"

Create a SQL table with autoincrement id and timestamps

CREATE TABLE `tutorials` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `title` varchar(255) DEFAULT NULL,   `description` varchar(255) DEFAULT NULL,   `published` tinyint(1) DEFAULT '1',   `createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,   `updatedAt` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,   PRIMARY KEY (`id`) ) 

Find out where is mysql data directory

'SHOW VARIABLES WHERE Variable_Name LIKE "%dir" 'SHOW VARIABLES WHERE Variable_Name = "datadir"'

Saving data to MySQL with Python

import mysql.connector from time import sleep import random import sys ## C:\ProgramData\MySQL\MySQL Server 8.0\my.ini ## https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html#caching-sha2-pluggable-authentication-installation try:     username = "yourusername"; password="yourpassword";     database="yourdatabase";host="localhost";     cnx = mysql.connector.connect(user=username, password=password,                                   host=host,database=database)     cursor = cnx.cursor()     print("Successfully connected to database!")          update = True     while update:         try:             value = random.randint(0,1024)              sensor_value = value       ...

mysql commands for working with the Cloudera VMs

Login mysql -uroot -pcloudera Dump a database to a file mysqldump -u root -p mydatabase > /home/myuser/database-dump.sql Restore mySQL dump file to a mySQL database mysql -u username -p database_name < file.sql mysqldump -u training -p trainingdatabase > /home/training/trainingdatabase-dump.sql mysql -u root -p loudacre < loudacredatabase-dump.sql mySQL commands SHOW DATABASES; CREATE DATABASE loudacre; use loudacre; show tables; mysql -u root -p loudacre -e "describe webpage" mysql -u root -p loudacre -e "select * from webpage limit 5"

How to use JSON, jQuery and mySQL in PHP

Image
Today, I dabbled for the first time with PHP, JSON, jQuery and mySQL. I am writing this post for my own reference as well as hoping that it will be useful for others who are trying to do something similar as I was. If you are too lazy to try out the code yourself, you can access this page to see a demo of what this code does . The code snippets provided below will help you to accomplish these tasks: Fetch data from a mySQL database and convert it to JSON data (demo_mysqltojson.php) Invoke an AJAX call to the PHP script above upon a button click using jQuery that returns JSON data, read and convert the JSON data to array-like records that can be iterated and used. (demo_showjsondata.php) Create a JSON array and send that JSON array via an AJAX call to a PHP script (demo_jsontomysql.php) that will add it to a mySQL database demo_mysqltojson.php <? $con = mysql_connect("localhost","demouser","demopassword"); if (!$con) { die('Could not ...

mysql newbie problem: Error 1045 (28000)

Image
Tried to install mysql Community Edition on my PC just now and encountered the error message as shown in the screenshot below: Error 1045 (28000): Access denied for user 'root@'localhost' (using password: NO) Fortunately, the problem is very easy to solve and needs you to specify to the SQL command-line interpreter that you want to specify a different password to log into the root account.  You just need to type "mysql -u root -p" and press Enter. The command-line tool will prompt you for your root password and once you supply the matching password, you will see the log-in screen as below: