三、安装后调整
1、对数据库目录进行权限设置
chown -R mysql:mysql /usr/local/mysql/
2、建立配置文件
vi /etc/my.cnf //原先的删掉插入新的
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES //固定格式
:x
chown mysql:mysql /etc/my.cnf
3、设置环境变量
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile //把这两个路径添加到环境变量中,并放到profile文件中使之开机自运行,否则不生效
echo ‘export PATH‘ >> /etc/profile //也可以软链接
source /etc/profile //立即生效
4、初始化数据库
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data //mysql初始化
5、添加系统服务
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld //启动数据库
netstat -anpt | grep 3306
systemctl enable mysqld //开机自启
6、设置数据密码
mysqladmin -u root -p password "123" //给root账号设置密码
7、登陆数据库
mysql -u root -p //数据库登陆成功,可以在里面进行操作了
原文地址:http://blog.51cto.com/13572519/2116742