(1)mySoftware:用于存放软件安装包
(2)mysql:安装mysql的文件夹
2、解压mysql安装包:tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql
3、进入mysql目录,依次执行下面命令:
4、启动MySQL服务
(1)systemctl start mysqld:启动mysql服务器
(2)systemctl restart mysqld:重启mysql服务器
(3)systemctl stop mysqld:停止mysql服务器
5、查询自动生成的root用户密码
6、修改root用户密码
登录到MySQL之后,需要将自动生成的不便记忆的密码修改了,修改成自己熟悉的便于记忆的密码。
ALTER USER 'root'@'localhost' IDENTIFIED BY '1234'
7、 默认的root用户只能当前节点localhost访问,是无法远程访问的,我们还需要创建一个root账户,用户远程访问
并给root用户分配权限
grant all on *.* to 'root'@'%'
1.首先在liunx下安装Mysql数据库~$ sudo apt-get install mysql-server #安装Mysql服务器端
~$ ps -aux|grep mysql #检查Mysql服务器进程
beili10301 0.0 0.0 37080 3604 pts/7S+5月20 0:00 mysql -u root -p
mysql25125 0.0 0.0 4472 1704 ?Ss 09:51 0:00 /bin/sh /usr/bin/mysqld_safe
mysql25496 0.0 3.1 859956 127084 ? Sl 09:51 0:01 /usr/sbin/mysqd --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
beili26652 0.0 0.0 13708 2180 pts/19 S+ 10:32 0:00 grep --color=auto mysql
~$ netstat -nlt|grep 3306 #检查Mysql服务器占用端口
tcp0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
~$ /etc/init.d/mysql status # 通过启动命令检查Mysql服务器状态
Loaded: loaded (/lib/systemd/system/mysql.serviceenabledvendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST43min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ service mysql status # 通过系统服务检查Mysql服务器状态
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.serviceenabledvendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST44min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ whereis mysql # 查看mysql各个文件安装的目录
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
2.访问和配置Mysql
$ mysql -u root -p
Enter password:
mysql默认的字符集为latin1的,所以要改为utf8的。很多网上的文章执行“sudo vi /etc/mysql/my.cnf”,可是打开一看,里面就两行话:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
想来mysql的配置文件应该是在那两个文件夹下面,于是尝试之下打开了/etc/mysql/mysql.conf.d/ 下的mysqld.cnf文件,执行下面的命令:
~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
...
[client]
default-character-set=utf8
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice= 0
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
...
注:棕色部分是添加的内容
重启mysql服务,并查看字符集的设置情况:
~$ sudo /etc/init.d/mysql restart
~$ mysql -u root -p
mysql>show variables like "%char%"
+--------------------------+----------------------------+
| Variable_name| Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results| utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
1、到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,
64位系统下载Linux - Generic (glibc 2.5) (x86, 64-bit),32位系统下载Linux - Generic (glibc 2.5) (x86, 32-bit)
2、解压32位安装包:
进入安装包所在目录,执行命令:tar mysql-5.6.17-linux-glibc2.5-i686.tar.gz
3、复制解压后的mysql目录到系统的本地软件目录:
执行命令:cp mysql-5.6.17-linux-glibc2.5-i686 /usr/local/mysql -r
4、添加系统mysql组和mysql用户:
执行命令:groupadd mysql和useradd -r -g mysql mysql
5、安装数据库:
进入安装mysql软件目录:执行命令 cd /usr/local/mysql
修改当前目录拥有者为mysql用户:执行命令?chown -R mysql:mysql ./
安装数据库:执行命令?./scripts/mysql_install_db --user=mysql
修改当前目录拥有者为root用户:执行命令?chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令?chown -R mysql:mysql data
到此数据库安装完毕
6、启动mysql服务和添加开机启动mysql服务:
添加开机启动:执行命令cp support-files/mysql.server /etc/init.d/mysql,把启动脚本放到开机初始化目录
启动mysql服务:执行命令service mysql start
执行命令:ps -ef|grep mysql 看到mysql服务说明启动成功
7、修改mysql的root用户密码,root初始密码为空的:
执行命令:./bin/mysqladmin -u root password '密码'
8、把mysql客户端放到默认路径:
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
注意:建议使用软链过去,不要直接包文件复制,便于系统安装多个版本的mysql
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)