1、centos7 默认yum源中没有mysql数据库,要想安装mysql则需要配置mysql源 cd /usr/local/src/ wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 2、community 是社区免费版本,我们一般都采用该版本添加源 rpm -ivh mysql57-community-release-el7-8.noarch.rpm 3、安装 yum install mysql-community-server4、查看状态 yum info mysql-community-server5、查看详细安装状态 rpm -ql mysql-community-server6、这里是mysql配置文件 vim /etc/my.cnf7、查看端口使用情况 ss -tanl8、启动mysql systemctl start mysqld9、查看状态 systemctl status mysqld ss -tanl vi /etc/my.cnf10、创建数据库数据存放目录 cd /usr/local/ mkdir mysql-data pwd11、修改数据库数据存目录配置文件 vi /etc/my.cnf 修改 datadir = /usr/local/mysql-data systemctl restart mysqld ss -tanl 完成复制代码
2、连接数据库
链接数据库:1、刚创建好的数据库是没有密码的,所以要查看一下 随机密码是多少使用命令:grep "password" /var/log/mysqld.log 查看2018-11-19T11:01:05.350139Z 1 [Note] A temporary password is generated for root@localhost: yP0T%KgAw(Ea2018-11-19T11:06:06.096574Z 0 [Note] Shutting down plugin 'validate_password'2018-11-19T11:06:07.812016Z 0 [Note] Shutting down plugin 'sha256_password'2018-11-19T11:06:07.812019Z 0 [Note] Shutting down plugin 'mysql_native_password'2018-11-19T11:06:09.091483Z 1 [Note] A temporary password is generated for root@localhost: uh8=c%LPK.-D这里注意随机密码我这里出现两个 "yP0T%KgAw(Ea" 和 "uh8=c%LPK.-D" 不知道原因,选择尝试一下,一般第二个好用2、连接数据库mysql -u root -p运行命令报错show database;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.说明必须先要修改数据库密码3、修改数据库密码alter user user() identified by "Root12@34%{"如果密码过于简单这里会提示密码过于简单,所以可以设置复杂点先4、查看数据库show database;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+5、测试链接数据库mysql -u root -pRoot12@34%{6、修改权限允许远程登录GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root12@34%{' WITH GRANT OPTION;7、退出登录exit;8、配置开机自启systemctl enable mysqld9、查看配置状况systemctl is-enabled mysqld复制代码
4、centos7 下安装mongoDb 4.0
1、首先增加repo源
vi /etc/yum.repos.d/mongodb-org-4.0.repo将下面内容拷贝进入[mongodb-org-4.0]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.0/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc保存退出安装yum install -y mongodb-org复制代码