MySql Archives - TEKSpace Blog https://blog.tekspace.io/category/mysql/ Tech tutorials for Linux, Kubernetes, PowerShell, and Azure Wed, 30 Aug 2023 14:48:13 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://blog.tekspace.io/wp-content/uploads/2023/09/cropped-Tekspace-logo-icon-32x32.png MySql Archives - TEKSpace Blog https://blog.tekspace.io/category/mysql/ 32 32 Reset MySql 8.0 root password on Windows https://blog.tekspace.io/reset-mysql-8-0-root-password-on-windows/ https://blog.tekspace.io/reset-mysql-8-0-root-password-on-windows/#respond Thu, 01 Oct 2020 13:30:16 +0000 https://blog.tekspace.io/index.php/2020/10/01/reset-mysql-8-0-root-password-on-windows/ If you forgot your root password and need to reset it for your MySql 8 server. Follow below guide. Stop MySQL80 service on Windows This will stop the MySQL80 service. If you wish to stop service from the services console, you can go to Start menu, select Control Panel, then Administrative Tools, then Services. Okay, […]

The post Reset MySql 8.0 root password on Windows appeared first on TEKSpace Blog.

]]>
If you forgot your root password and need to reset it for your MySql 8 server. Follow below guide.

Stop MySQL80 service on Windows

  1. Open PowerShell as Administrator and execute the below command.
get-service -Name mysql* | Stop-Service

This will stop the MySQL80 service. If you wish to stop service from the services console, you can go to Start menu, select Control Panel, then Administrative Tools, then Services.

Okay, now that we have stopped the service. Let’s proceed with root password reset.

MySQL Root Password Reset

  1. Create a file called reset.txt on your computer at c:\reset.txt.
  2. Copy and paste below to reset.txt file and replace password with your own password and save.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
  1. Open Command promote and go to bin path
cd C:\Program Files\MySQL\MySQL Server 8.0\bin
  1. Execute below command to reset password:
mysqld.exe --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --datadir="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Data" --init-file=c:\\reset.txt --console

Your output should look something like this:

C:\Program Files\MySQL\MySQL Server 8.0\bin>2020-10-01T13:06:32.497917Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.21)  MySQL Community Server - GPL.
mysqld.exe --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --datadir="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Data" --init-file=c:\\reset.txt --console
2020-10-01T13:06:36.133710Z 0 [Warning] [MY-000081] [Server] option 'read_buffer_size': unsigned value 614 adjusted to 8192.
2020-10-01T13:06:36.133802Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-10-01T13:06:36.135314Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.21) starting as process 9284
2020-10-01T13:06:36.149595Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-10-01T13:06:36.942139Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-10-01T13:06:37.269023Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2020-10-01T13:06:37.392127Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-10-01T13:06:37.392634Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-10-01T13:06:37.486710Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.21'  socket: ''  port: 3306  MySQL Community Server - GPL.
2020-10-01T13:06:53.165055Z 9 [Warning] [MY-013360] [Server] Plugin sha256_password reported: ''sha256_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
2020-10-01T13:06:59.761228Z 0 [System] [MY-013105] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Normal shutdown.

Once the password reset is completed. You can go ahead and start the MySQL80 service.

get-service -Name mysql* | Start-Service

If you wish to stop service from services console, you can go to Start menu, select Control Panel, then Administrative Tools, then Services and start MySql80 service.

The post Reset MySql 8.0 root password on Windows appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/reset-mysql-8-0-root-password-on-windows/feed/ 0
How to create new MySQL user and assign database https://blog.tekspace.io/how-to-create-new-mysql-user-and-assign-database/ https://blog.tekspace.io/how-to-create-new-mysql-user-and-assign-database/#respond Mon, 21 Sep 2020 18:42:17 +0000 https://blog.tekspace.io/index.php/2020/09/21/how-to-create-new-mysql-user-and-assign-database/ To create a new user in MySQL follow the below steps: Create new MySQL user Once the user is created, you will need to set permissions to grant access to the database. Here I will first create a testdb to create a new database to set permissions. Create new database Assign permissions to database Update […]

The post How to create new MySQL user and assign database appeared first on TEKSpace Blog.

]]>
To create a new user in MySQL follow the below steps:

Create new MySQL user

CREATE USER 'demo'@'localhost' IDENTIFIED BY 'dem0123';

Once the user is created, you will need to set permissions to grant access to the database. Here I will first create a testdb to create a new database to set permissions.

Create new database
CREATE DATABASE testdb;
Assign permissions to database
GRANT ALL PRIVILEGES ON testdb.* TO 'demo'@'localhost';

Update changes by executing the below command:

FLUSH PRIVILEGES;

Drop user

DROP USER 'demo'@'localhost';

Validate permissions

SHOW GRANTS FOR 'demo'@'localhost';

Output:

+----------------------------------------------------------------+
| Grants for demo@localhost                                |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO `demo`@`localhost`                 |
| GRANT ALL PRIVILEGES ON `testdb`.* TO `demo`@`localhost` |
+----------------------------------------------------------------+
2 rows in set (0.00 sec)

Allowing remote access for MySQL 8 server

In MySQL 8 on Centos 8 server, edit /etc/my.cnf file and add the following line at the end and save:

bind-address            = 0.0.0.0

You can reference this tutorial here for any further details.

Create user

CREATE USER 'demo'@'10.1.1.%' IDENTIFIED BY 'password';

Grant privileges

GRANT ALL ON testdb.* TO 'demo'@'10.1.1.%';
FLUSH PRIVILEGES;

The post How to create new MySQL user and assign database appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-create-new-mysql-user-and-assign-database/feed/ 0
How to install MySQL 8 on CentOS 8 https://blog.tekspace.io/how-to-install-mysql-8-on-centos-8/ https://blog.tekspace.io/how-to-install-mysql-8-on-centos-8/#respond Sat, 19 Sep 2020 16:58:02 +0000 https://blog.tekspace.io/index.php/2020/09/19/how-to-install-mysql-8-on-centos-8/ Download rpm package and configure yum repository Disable mysql5.7: Enable mysql8.0: Verify: Disabling default MySQL modules Installation Service start stop start: status check: Changing temp password after installation The above output will display the default password Z#5m,9wsmlw in the console. Changing password by following below setup command Interactive setup: Connecting to MySQL server

The post How to install MySQL 8 on CentOS 8 appeared first on TEKSpace Blog.

]]>
Download rpm package and configure yum repository
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
sudo yum localinstall mysql80-community-release-el8-1.noarch.rpm
sudo yum repolist enabled | grep "mysql.*-community.*"

output:
mysql-connectors-community              MySQL Connectors Community
mysql-tools-community                   MySQL Tools Community
mysql80-community                       MySQL 8.0 Community Server
sudo yum repolist all | grep mysql

Disable mysql5.7:

sudo yum-config-manager --disable mysql57-community

Enable mysql8.0:

sudo yum-config-manager --enable mysql80-community

Verify:

sudo yum repolist enabled | grep mysql

Disabling default MySQL modules

sudo yum module disable mysql

Installation

sudo yum install mysql-community-server

Service start stop

start:

sudo service mysqld start

status check:

sudo service mysqld status

Changing temp password after installation

sudo grep 'temporary password' /var/log/mysqld.log

output:
2020-09-19T16:33:12.280169Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: .Z#5m,9wsmlw

The above output will display the default password Z#5m,9wsmlw in the console.

Changing password by following below setup command

sudo mysql_secure_installation

Interactive setup:

Securing the MySQL server deployment.

Enter password for user root: Enter New Root Password

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: Set New MySQL Password

Re-enter new password: Re-enter New MySQL Password

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

Connecting to MySQL server

mysql -u root -p

The post How to install MySQL 8 on CentOS 8 appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-install-mysql-8-on-centos-8/feed/ 0
How to Deploy MySQL database on Digital Ocean Managed Kubernetes Cluster https://blog.tekspace.io/how-to-deploy-mysql-database-on-digital-ocean-managed-kubernetes-cluster/ https://blog.tekspace.io/how-to-deploy-mysql-database-on-digital-ocean-managed-kubernetes-cluster/#respond Mon, 14 Sep 2020 18:40:34 +0000 https://blog.tekspace.io/index.php/2020/09/14/how-to-deploy-mysql-database-on-digital-ocean-managed-kubernetes-cluster/ NOTE: This tutorial assumes you know how to connect to a Kubernetes cluster. Create secrets to securely store MySQL credentials Output: Persistant volume and MySQL deployment Execute the below command to create persistent volume: Output: Execute the below command to deploy MySQL pod: Output: Exposing MySQL as a Service Output: Output:

The post How to Deploy MySQL database on Digital Ocean Managed Kubernetes Cluster appeared first on TEKSpace Blog.

]]>

NOTE: This tutorial assumes you know how to connect to a Kubernetes cluster.

Create secrets to securely store MySQL credentials

  1. Guide on how to create base 64 encoded values:

    Windows 10 guideLinux guide

  2. Create a new file called: mysql-secret.yaml and paste the value below.
    NOTE: You must first capture the value in base 64 by following the guide in step 1.
---
apiVersion: v1
kind: Secret
metadata:
  name: mysqldb-secrets
type: Opaque
data:
  ROOT_PASSWORD: c3VwZXItc2VjcmV0LXBhc3N3b3JkLWZvci1zcWw= 
  1. Execute the below command to create secrets:
kubectl apply -f mysql-secret.yaml

Output:

secret/mysqldb-secrets created
  1. To see if the secret is created, execute the below command:
kubectl get secret
NAME                  TYPE                                  DATA   AGE
default-token-jqq69   kubernetes.io/service-account-token   3      6h20m
echo-tls              kubernetes.io/tls                     2      5h19m
mysqldb-secrets       Opaque                                1      42s
  1. To see the description of the secret, execute the below command:
kubectl describe secret mysqldb-secrets
Name:         mysqldb-secrets
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
ROOT_PASSWORD:  29 bytes

Persistant volume and MySQL deployment

  1. Create a persistent volume YAML file called: mysql-pvc.yaml and paste the following values:
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pvc
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/mysql-data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: do-block-storage
  1. Create a new deployment YAML file called: mysql-deployment.yaml and paste the following values:
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysqldb-secrets
              key: ROOT_PASSWORD
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pvc-claim

Execute the below command to create persistent volume:

kubectl apply -f mysql-pvc.yaml

Output:

persistentvolume/mysql-pvc createdpersistentvolumeclaim/mysql-pvc-claim created

Execute the below command to deploy MySQL pod:

kubectl apply -f mysql-deployment.yaml

Output:

service/mysql created

Exposing MySQL as a Service

  1. Create a file called mysql-service.yaml and paste the following values:
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  selector:
    app: mysql
  ports:
  - protocol: TCP
    port: 3306
    targetPort: 3306
  1. Execute the below command to create a service for MySQL:
kubectl apply -f mysql-service.yaml

Output:

service/mysql-service created
  1. To confirm if the service is created successfully, execute the below command:
kubectl get svc

Output:

NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
echo1           ClusterIP   10.245.179.199   <none>        80/TCP     6h4m
echo2           ClusterIP   10.245.58.44     <none>        80/TCP     6h2m
kubernetes      ClusterIP   10.245.0.1       <none>        443/TCP    6h33m
mysql           ClusterIP   None             <none>        3306/TCP   4m57s
mysql-service   ClusterIP   10.245.159.76    <none>        3306/TCP   36s

The post How to Deploy MySQL database on Digital Ocean Managed Kubernetes Cluster appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-deploy-mysql-database-on-digital-ocean-managed-kubernetes-cluster/feed/ 0