CentOS 安装Mysql教程

First, Completely Removing MySQL Server in CentOS

Step 1: Check list the mysql rpm which is installed on server

#rpm -qa | grep mysql
or
#yum list installed | grep mysql

Step 2 : Removing all mysql-related packages (with “yum remove”)

#yum remove mysql-client mysql-server mysql-common mysql-devel
Step 3: Delete the databases folder

#rm -rf /var/lib/mysql/
#rm -rf /etc/my.cnf

second,安装mysql 教程:

确保已经设置好hostname:

hostname
hostname -f

更新你的系统:
sudo yum update

Mysql必须安装社区版本:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update

在安装的过程中,会提示你是否下载相应的文件,输入 y ok。

sudo yum install mysql-server
sudo systemctl start mysqld

Harden MySQL Server

  1. Run the mysql_secure_installation script to address several security concerns in a default MySQL installation.

    1
     sudo mysql_secure_installation
    

You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options.


root 用户登录:

mysql -u root -p

输入上一步你输入的密码,出现:

mysql>

测试:

create database testdb;
 create user 'testuser'@'localhost' identified by 'password';
 grant all on testdb.* to 'testuser' identified by 'password';

退出mysql:

exit

Create a Sample Table

  1. Log back in as testuser.

    1
    mysql -u testuser -p
    
  2. Create a sample table called customers. This creates a table with a customer ID field of the type INT for integer (auto-incremented for new records, used as the primary key), as well as two fields for storing the customer’s name.

    1
    2
    use testdb;
    create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
    
  3. Then exit MySQL.

    1
    exit
    

Reset the MySQL Root Password

If you forget your root MySQL password, it can be reset.

  1. Stop the current MySQL server instance, then restart it with an option to not ask for a password.

    1
    2
    sudo systemctl stop mysqld
    sudo mysqld_safe --skip-grant-tables &
    
  2. Reconnect to the MySQL server with the MySQL root account.

    1
    mysql -u root
    
  3. Use the following commands to reset root’s password. Replace password with a strong password.

    1
    2
    3
    4
    use mysql;
    update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
    flush privileges;
    exit
    
  4. Then restart MySQL.

    1
    sudo systemctl start mysqld
    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值