我这是centos系统,ubantu不适用!!!
我这是centos系统,ubantu不适用!!!
点击右下角展开,否则没有自动换行!!!!
点击右下角展开,否则没有自动换行!!!!
点击右下角展开,否则没有自动换行!!!!
重要的事情说三遍
练习用的话直接yum -y install mysql mysql-server
也可以使用源码安装
先把rpm格式的mysql删除,否则初始化失败rpm -e mysql-server mysql --nodeps //忽略依赖关系删除
yum -y install ncurses-devel //安装依赖包
tar xf cmake-2.8.12.tar.gz -C /usr/src/ //mysql需要cmake支持
cd /usr/src/cmake-2.8.12/ //进入解压路径
./configure &&gmake &&gmake install //安装cmake
groupadd mysql //创建mysql组
useradd -M -s /sbin/nologin -g mysql mysql//创建mysql用户,并加入mysql组里
tar xf mysql-5.7.2-m12.tar.gz -C /usr/src/ //解压mysqlcd /usr/src/mysql-5.7.2-m12///进入解压路径
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc &&make &&make install //安装选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //主程序安装目录
-DDEFAULT_CHARSET=utf8 //默认字符集为 utf8
-DDEFAULT_COLLATION=utf8_general_ci //默认的字符集校对规则
-DWITH_EXTRA_CHARSETS=all //安装所有字符集
-DSYSCONFDIR=/etc //配置文件存放目录
make &&make install //开始make
优化步骤
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
. /etc/profile //注意“.”后面有空格
chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql //初始化
--basedir=/usr/local/mysql/ //指定安装目录(产品目录)
--datadir=/usr/local/mysql/data //指定数据目录
--user=mysql//指定用户身份
service mysqld start
Starting MySQL.............. [确定]
mysqladmin -u root password '123456'//设置成自己的密码
我是5.7的版本有可能一定几率启动时报错,看下mysql的配置文件,里面的mysql.sock文件找不到,解决方法如下:
find / -name mysql.sock
找到后复制这个路径
vim /etc/my.cnf
找到sock=/data/sock这一行,把后面的路径改成刚才找到的路径然后重启mysql即可。
如果还报错就告诉我
创建用于执行mysql服务程序的帐号:[root@linuxprobe cmake-2.8.11.2]# cd ..
[root@linuxprobe src]# useradd mysql -s /sbin/nologin
创建数据库程序和文件的目录,并设置目录的所属与所组:
[root@linuxprobe src]# mkdir -p /usr/local/mysql/var
[root@linuxprobe src]# chown -Rf mysql:mysql /usr/local/mysql
安装Mysql服务程序(解压与编译过程已省略):
[root@linuxprobe src]# tar xzvf mysql-5.6.19.tar.gz
[root@linuxprobe src]# cd mysql-5.6.19/
[root@linuxprobe mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc
[root@linuxprobe mysql-5.6.19]# make
[root@linuxprobe mysql-5.6.19]# make install
删除系统默认的配置文件:
[root@linuxprobe mysql-5.6.19]# rm -rf /etc/my.cnf
生成系统数据库(生成信息已省略):
[root@linuxprobe mysql-5.6.19]# cd /usr/local/mysql
[root@linuxprobe mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var
创建配置文件的软连接文件:
[root@linuxprobe mysql]# ln -s my.cnf /etc/my.cnf
将mysqld服务程序添加到开机启动项:
[root@linuxprobe mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@linuxprobe mysql]# chmod 755 /etc/init.d/mysqld
[root@linuxprobe mysql]# chkconfig mysqld on
编辑启动项的配置文件:
[root@linuxprobe mysql]# vim /etc/rc.d/init.d/mysqld
//分别修改第46与47行,basedir为程序安装路径,datadir为数据库存放目录。
basedir=/usr/local/mysql
datadir=/usr/local/mysql/var
重启mysqld服务程序:
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!
把mysql服务程序命令目录添加到环境变量中(永久生效):
[root@linuxprobe mysql]# vim /etc/profile
//在配置文件的最下面追加:
export PATH=$PATH:/usr/local/mysql/bin
[root@linuxprobe mysql]# source /etc/profile
将mysqld服务程序的库文件链接到默认的位置:
[root@linuxprobe mysql]# mkdir /var/lib/mysql
[root@linuxprobe mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@linuxprobe mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@linuxprobe mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
初始化mysqld服务程序:
[root@linuxprobe mysql]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password: 输入要为root用户设置的数据库密码。
Re-enter new password: 重复再输入一次密码。
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y(删除匿名帐号)
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y(禁止root用户从远程登陆)
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y(删除test数据库并取消对其的访问权限)
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y(刷新授权表,让初始化后的设定立即生效)
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
可以百度搜索Linux就该这么学,第9章 使用Apache服务部署静态网站,里面有部署mysql的资料
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)