安装mysql
下载、添加和更新mysql源 centos 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
安装启动mysql服务
sudo yum install mysql-server
sudo systemctl start mysqld
安全设置
sudo mysql_secure_installation
运行上面的命令会寻味是否修改root密码,删除匿名账号、限制root远程登录、删除test数据库等。
使用mysql
可以通过mysql客户端访问mysql服务,他已经和mysq-server一同安装了,可以从终端中访问。
登录mysql服务
使用root账号登录
mysql -u root -p
当提示输入密码时,输入在mysql_secure_installation时设置的密码
成功后出现如下提示:
mysql>
显示所有可以使用的命令输入h
创建一个新的mysql用户和数据库
下面数据库的名字是testdb,用户是testuser 密码是pasword
create database testdb;
create user 'testuser'@'localhost' identified by 'password';
grant all on testdb.* to 'testuser' identified by 'password';
创建数据库并赋予用户权限
create database testdb;
grant all on testdb.* to 'testuser' identified by 'password';
退出mysql服务
exit
创建一个表
登录testuser
mysql -u testuser -p
创建一个表customers,主键id
use testdb;
create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
重置root的密码
首先停止服务,修改配置登录不需要密码,重启
sudo systemctl stop mysqld
sudo mysqld_safe --skip-grant-tables &
root 登录
mysql -u root
如下设置root密码
use mysql;
update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit
重启mysql服务
sudo systemctl start mysqld
https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7