CentOS 7 版本中 MySQL数据库已从默认的程序列表中移除,所以在安装前我们需要先去官网下载 Yum 资源包,
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
$ rpm -ivh mysql-community-release-el7-5.noarch.rpm
$ yum update
安装mysql
$ yum install mysql-server
权限设置:
chown -R mysql:mysql /var/lib/mysql
初始化 MySQL:
mysqld --initialize
启动 MySQL:
systemctl start mysqld
查看 MySQL 运行状态:
systemctl status mysqld
设置root管理员密码
mysqladmin -u root password "root密码"
连接mysql
$ mysql -uroot 登录无未设置密码的root账号
mysql -uroot -proot
注意-u和-p后面没有空格
或:
mysql -u root -p
> show databases; 查看所有数据库
> use mysql; 切换数据库
> SELECT host, user, password FROM user WHERE user = 'root';
允许远程连接
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
> which mysql 查看mysql安装路径
> /user/bin/mysql