Create new mysql dataabse centos 7
Here are the steps to create a new MySQL database on CentOS 7:
Step 1: Install MySQL
If you haven't already, install MySQL on your CentOS 7 system. You can do this by running the following command:
sudo yum install mysql-server
Step 2: Start the MySQL Service
Start the MySQL service by running the following command:
sudo systemctl start mysqld
Step 3: Secure the MySQL Installation
Run the following command to secure the MySQL installation:
sudo mysql_secure_installation
This will prompt you to set a root password, remove anonymous user accounts, and disable remote root login.
Step 4: Create a New Database
Log in to the MySQL shell by running the following command:
sudo mysql -u root -p
Enter the root password you set earlier.
Create a new database by running the following command:
CREATE DATABASE mydatabase;
Replace mydatabase
with the name you want to give your database.
Step 5: Create a New User and Grant Permissions
Create a new user and grant them permissions to the database by running the following commands:
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'%';
Replace myuser
and mypassword
with the username and password you want to use.
Step 6: Flush the Privileges
Flush the privileges by running the following command:
FLUSH PRIVILEGES;
Step 7: Exit the MySQL Shell
Exit the MySQL shell by running the following command:
quit
That's it! You have now created a new MySQL database on CentOS 7.
Additional Tips
- You can verify that the database was created by running the following command:
mysql -u myuser -pmypassword mydatabase
This should log you in to the database.
- You can also use the
mysql
command to create a new database and user in one step:mysql -u root -p -e "CREATE DATABASE mydatabase; CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'%'; FLUSH PRIVILEGES;"
Replace
mydatabase
,myuser
, andmypassword
with the desired values.