最近新换了工作,新的公司项目中服务器用的是Linux,虽然以前有自学过,但是都没有用到正式的环境中,为了能更快的融入新项目、新环境,就利用空闲时间自己鼓捣公司里面的东西,首先就从最基本的如何安装数据库开始!
1.虚拟机环境下的Linux或者说服务器Linux,根据自身情况,博主是自身学习用所以就选择了虚拟机下的CentOS7的Linux环境。
2.MySql安装包下载,
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
也可以到MySQL的官网进行下载或者说自行搜索,博主最后也提供了下载链接。
3.在/usr/local/下创建mysql目录并添加mysql用户和组
groupadd mysql
useradd -r -g mysql mysql
1.解压
tar -xzf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
注:安装目录需要设置到解压目录,否则报以下错误
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
or
FATAL ERROR: Could not find my-default.cnf
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
2.将解压的目录放到/usr/local下改为mysql或添加软连接,如果存在mysql目录,那就将解压目录下的文件放到/usr/local/mysql/目录下
mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
or
ln -s /www/mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
3.修改mysql目录及子文件属主和属组
chown -R mysql:mysql mysql
4.进入mysql目录并安装
cd /usr/local/mysql/
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
./mysql.server start
启动数据库。
1.CentOS7下用了systemctl替换了 service命令来管理开机自启动服务
参考:redhat文档:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html#sect-Managing_Services_with_systemd-Services-List
查看全部服务命令:
systemctl list-unit-files --type service
查看服务
systemctl status name.service
启动服务
systemctl start name.service
停止服务
systemctl stop name.service
重启服务
systemctl restart name.service增加开机启动
systemctl enable name.service
删除开机启动
systemctl disable name.service
其中.service 可以省略。
2.MySQL增加启动参数
2.1增加mysql.service
在/usr/lib/systemd/system目录下增加mysql.service,目录必须是绝对目录。
[Unit]
Description=MySql
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/mysql/data/mysql.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[unit]配置了服务的描述,规定了在network启动之后执行。[service]配置服务的pid,服务的启动,停止,重启。[install]配置了使用用户。
2.2使用mysql.service
#配置开机启动
systemctl enable mysql
#启动mysql
systemctl start mysql
#停止mysql
systemctl stop mysql
#重启mysql
systemctl restart mysql
wget http://www.cpan.org/src/5.0/perl-5.22.0.tar.gz
tar -zxvf perl-5.22.0.tar.gz
cd perl-5.22.0/
./Configure -des -Dprefix=$HOME/localperl
make
make test
make install
如果安装成功后还是报perl依赖的错误,那就安装perl-Module-Install.noarch这个模块
yum install -y perl-Module-Install.noarch
其他发行版本请自行搜索安装命令
# /usr/local/mysql/support-files/mysql.server stop
# mysqld_safe --skip-grant-table
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
rm -rf /etc/my.cnf
具体的错误信息如果以后碰到了再贴上来。